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,72 @@
|
|
|
1
|
+
// Antigravity CLI (`agy`) adapter. Paths confirmed on agy 1.4.12 in CI.
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { OWNED_MARK } from '../fsops.mjs';
|
|
4
|
+
import { tierFor, modelFor } from '../render.mjs';
|
|
5
|
+
import { localServer } from './opencode-v2.mjs';
|
|
6
|
+
import { skillSource, skillsCli } from '../pins.mjs';
|
|
7
|
+
|
|
8
|
+
const TOOLS = {
|
|
9
|
+
'read-only': ['view_file', 'grep_search', 'find_by_name'],
|
|
10
|
+
'git-read': ['view_file', 'grep_search', 'find_by_name', 'run_command'],
|
|
11
|
+
'read-write': ['view_file', 'grep_search', 'find_by_name', 'run_command', 'write_to_file', 'replace_file_content'],
|
|
12
|
+
};
|
|
13
|
+
const WEB = ['search_web', 'read_url_content'];
|
|
14
|
+
|
|
15
|
+
export function renderAntigravityAgent(agent, profile) {
|
|
16
|
+
const tier = tierFor(profile, agent.name, agent.tier);
|
|
17
|
+
const tools = [...TOOLS[agent.access], ...(agent.name === 'research' ? WEB : [])];
|
|
18
|
+
return [
|
|
19
|
+
'---',
|
|
20
|
+
`# ${OWNED_MARK} (tier: ${tier})`,
|
|
21
|
+
`name: ${agent.name}`,
|
|
22
|
+
`description: ${agent.description}`,
|
|
23
|
+
'subagent: true',
|
|
24
|
+
`model: ${modelFor(profile, tier)?.model ?? 'inherit'}`,
|
|
25
|
+
'tools:',
|
|
26
|
+
...tools.map((t) => `- ${t}`),
|
|
27
|
+
'---',
|
|
28
|
+
'',
|
|
29
|
+
agent.body,
|
|
30
|
+
'',
|
|
31
|
+
].join('\n');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const skills = (tool, desc, repo, names) => ({
|
|
35
|
+
tool,
|
|
36
|
+
desc,
|
|
37
|
+
run: [['npx', '-y', skillsCli(), 'add', repo, '--skill', ...names, '-a', 'antigravity-cli', '-g', '-y']],
|
|
38
|
+
// Without -a: `remove -a` keeps ~/.agents/skills while another detected agent may share that folder.
|
|
39
|
+
undo: [['npx', '-y', skillsCli(), 'remove', ...names, '-g', '-y']],
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export function antigravityAdapter({ home, core, profile, opts, rules, adhdCommand }) {
|
|
43
|
+
const dir = path.join(home, '.gemini', 'config');
|
|
44
|
+
const tools = opts.tools;
|
|
45
|
+
const actions = [{ kind: 'file', path: path.join(dir, 'rules', 'lean-agents.md'), content: rules }];
|
|
46
|
+
const commands = [];
|
|
47
|
+
|
|
48
|
+
for (const agent of core.agents) {
|
|
49
|
+
actions.push({ kind: 'file', path: path.join(dir, 'agents', `${agent.name}.md`), content: renderAntigravityAgent(agent, profile) });
|
|
50
|
+
}
|
|
51
|
+
const edits = [];
|
|
52
|
+
for (const name of ['serena', 'playwright'].filter((t) => tools.includes(t))) {
|
|
53
|
+
const [command, ...args] = localServer(core, name).command;
|
|
54
|
+
edits.push({ path: ['mcpServers', name], value: { command, args }, mode: 'setIfAbsent' });
|
|
55
|
+
}
|
|
56
|
+
if (edits.length) actions.push({ kind: 'json', path: path.join(dir, 'mcp_config.json'), edits });
|
|
57
|
+
|
|
58
|
+
if (tools.includes('rtk')) {
|
|
59
|
+
commands.push({ tool: 'rtk', desc: 'RTK plugin for Antigravity', run: [['rtk', 'init', '-g', '--agent', 'antigravity']], undo: [['rtk', 'init', '-g', '--agent', 'antigravity', '--uninstall']] });
|
|
60
|
+
}
|
|
61
|
+
if (tools.includes('context-mode')) {
|
|
62
|
+
// Context Mode 2.x dropped its Antigravity plugin and `context-mode setup --list` has no antigravity agent (2.1.4).
|
|
63
|
+
console.log('Context Mode has no Antigravity setup in v2: skipped. Check `context-mode setup --list` for support.');
|
|
64
|
+
}
|
|
65
|
+
if (tools.includes('caveman')) {
|
|
66
|
+
commands.push(skills('caveman', 'Caveman skills for Antigravity', skillSource('caveman'), ['caveman', 'caveman-compress', 'caveman-stats']));
|
|
67
|
+
}
|
|
68
|
+
if (tools.includes('i-have-adhd')) {
|
|
69
|
+
commands.push(skills('i-have-adhd', 'i-have-adhd skill for Antigravity', skillSource('i-have-adhd'), ['i-have-adhd']), adhdCommand);
|
|
70
|
+
}
|
|
71
|
+
return { actions, commands };
|
|
72
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Claude Code adapter. Files only under ~/.claude; MCP servers and plugins go through
|
|
2
|
+
// the `claude` CLI so ~/.claude.json (which holds auth) is never edited directly.
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { OWNED_MARK } from '../fsops.mjs';
|
|
5
|
+
import { tierFor, modelFor } from '../render.mjs';
|
|
6
|
+
import { privacyOf } from '../network.mjs';
|
|
7
|
+
import { statuslineScript } from '../copilot-usage.mjs';
|
|
8
|
+
import { marketplaceSource, skillSource, skillsCli } from '../pins.mjs';
|
|
9
|
+
|
|
10
|
+
// Also the key of its record in state.json: removing the entry replaces that record (empty undo), so --uninstall does not remove it twice.
|
|
11
|
+
const CTX_MCP = 'Context Mode MCP server (user scope)';
|
|
12
|
+
const TOOLS = {
|
|
13
|
+
'read-only': 'Read, Grep, Glob',
|
|
14
|
+
'git-read': 'Read, Grep, Glob, Bash(git diff:*), Bash(git log:*), Bash(git show:*), Bash(git status:*)',
|
|
15
|
+
'read-write': null,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Web tools are dropped when other outbound calls are off.
|
|
19
|
+
export function renderClaudeAgent(agent, profile, web) {
|
|
20
|
+
const tier = tierFor(profile, agent.name, agent.tier);
|
|
21
|
+
const model = modelFor(profile, tier)?.model ?? 'inherit';
|
|
22
|
+
let tools = TOOLS[agent.access];
|
|
23
|
+
if (agent.name === 'research' && tools && web) tools += ', WebFetch, WebSearch';
|
|
24
|
+
const lines = [
|
|
25
|
+
'---',
|
|
26
|
+
`# ${OWNED_MARK} (tier: ${tier})`,
|
|
27
|
+
`name: ${agent.name}`,
|
|
28
|
+
`description: ${agent.description}`,
|
|
29
|
+
`model: ${model}`,
|
|
30
|
+
];
|
|
31
|
+
if (tools) lines.push(`tools: ${tools}`);
|
|
32
|
+
lines.push('---', '', agent.body, '');
|
|
33
|
+
return lines.join('\n');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const plugin = (repo, id) => ({
|
|
37
|
+
run: [['claude', 'plugin', 'marketplace', 'add', repo], ['claude', 'plugin', 'install', id]],
|
|
38
|
+
undo: [['claude', 'plugin', 'uninstall', id]],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export function claudeAdapter({ home, core, profile, opts, rulesPath, adhdCommand }) {
|
|
42
|
+
const dir = path.join(home, '.claude');
|
|
43
|
+
const actions = [];
|
|
44
|
+
const commands = [];
|
|
45
|
+
const tools = opts.tools;
|
|
46
|
+
|
|
47
|
+
actions.push({ kind: 'block', path: path.join(dir, 'CLAUDE.md'), body: `@${rulesPath}` });
|
|
48
|
+
for (const agent of core.agents) {
|
|
49
|
+
actions.push({ kind: 'file', path: path.join(dir, 'agents', `${agent.name}.md`), content: renderClaudeAgent(agent, profile, opts.network.outbound !== 'off') });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const env = { BASH_MAX_OUTPUT_LENGTH: '15000', CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: '80' };
|
|
53
|
+
const edits = Object.entries(env).map(([k, v]) => ({ path: ['env', k], value: v, mode: 'setIfAbsent' }));
|
|
54
|
+
edits.unshift({ path: ['model'], value: profile?.main_model ?? 'sonnet', mode: 'setIfAbsent' });
|
|
55
|
+
const net = opts.network;
|
|
56
|
+
const off = [
|
|
57
|
+
...(net.autoUpdate === 'off' ? ['DISABLE_AUTOUPDATER'] : []),
|
|
58
|
+
...(net.telemetry === 'off' ? ['DISABLE_TELEMETRY', 'DISABLE_ERROR_REPORTING'] : []),
|
|
59
|
+
...(net.outbound === 'off' ? ['DISABLE_BUG_COMMAND'] : []),
|
|
60
|
+
// Also stops updates and telemetry, so only when every category is off.
|
|
61
|
+
...(privacyOf(net) === 'strict' ? ['CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC'] : []),
|
|
62
|
+
...(net.telemetry === 'off' ? ['DO_NOT_TRACK'] : []),
|
|
63
|
+
];
|
|
64
|
+
for (const k of off) edits.push({ path: ['env', k], value: '1', mode: 'set' });
|
|
65
|
+
if (tools.includes('copilot-usage')) {
|
|
66
|
+
// Only when the user has no statusLine (setIfAbsent); uninstall removes it only while it is still ours. Forward slashes: Claude runs it through bash, also on Windows.
|
|
67
|
+
const script = path.join(dir, 'lean-copilot-usage-statusline.mjs');
|
|
68
|
+
actions.push({ kind: 'file', path: script, content: statuslineScript() });
|
|
69
|
+
const q = (p) => `"${p.replaceAll('\\', '/')}"`;
|
|
70
|
+
edits.push({ path: ['statusLine'], value: { type: 'command', command: `${q(process.execPath)} ${q(script)}` }, mode: 'setIfAbsent', keepIfChanged: true });
|
|
71
|
+
}
|
|
72
|
+
actions.push({ kind: 'json', path: path.join(dir, 'settings.json'), edits });
|
|
73
|
+
|
|
74
|
+
if (tools.includes('rtk')) {
|
|
75
|
+
commands.push({ tool: 'rtk', desc: 'RTK hook for Claude Code', run: [['rtk', 'init', '-g', '--auto-patch']], undo: [['rtk', 'init', '-g', '--uninstall']] });
|
|
76
|
+
}
|
|
77
|
+
if (tools.includes('context-mode') && opts.toolNode) {
|
|
78
|
+
// The plugin starts its server with the first `node` on PATH, so on an old Node it registers the absolute server instead (hooks and skills are lost).
|
|
79
|
+
commands.push({
|
|
80
|
+
tool: 'context-mode',
|
|
81
|
+
desc: CTX_MCP,
|
|
82
|
+
run: [['claude', 'mcp', 'add', '--scope', 'user', 'context-mode', '--', ...core.mcp['context-mode'].command]],
|
|
83
|
+
undo: [['claude', 'mcp', 'remove', '--scope', 'user', 'context-mode']],
|
|
84
|
+
skipIfOutput: { cmd: ['claude', 'mcp', 'get', 'context-mode'], ok: true },
|
|
85
|
+
});
|
|
86
|
+
} else if (tools.includes('context-mode')) {
|
|
87
|
+
// An earlier run on an old Node registered the absolute MCP server; the plugin runs its own, so lean-agents removes the one it added.
|
|
88
|
+
if ((opts.prior ?? []).some((c) => c.desc === CTX_MCP && c.undo?.length)) {
|
|
89
|
+
commands.push({ tool: 'context-mode', desc: CTX_MCP, run: [['claude', 'mcp', 'remove', '--scope', 'user', 'context-mode']], undo: [] });
|
|
90
|
+
}
|
|
91
|
+
commands.push({ tool: 'context-mode', desc: 'Context Mode plugin', ...plugin(marketplaceSource('context-mode-plugin'), 'context-mode@context-mode') });
|
|
92
|
+
}
|
|
93
|
+
if (tools.includes('ponytail')) {
|
|
94
|
+
commands.push({ tool: 'ponytail', desc: 'Ponytail plugin', ...plugin(marketplaceSource('ponytail-plugin'), 'ponytail@ponytail') });
|
|
95
|
+
}
|
|
96
|
+
if (tools.includes('i-have-adhd')) {
|
|
97
|
+
commands.push({ tool: 'i-have-adhd', desc: 'i-have-adhd plugin', ...plugin(marketplaceSource('i-have-adhd'), 'i-have-adhd@i-have-adhd') }, adhdCommand);
|
|
98
|
+
if (opts.adhdAlways) actions.push({ kind: 'file', path: path.join(dir, '.i-have-adhd-always'), content: '' , force: true });
|
|
99
|
+
}
|
|
100
|
+
for (const name of ['serena', 'playwright']) {
|
|
101
|
+
if (!tools.includes(name)) continue;
|
|
102
|
+
const server = core.mcp[name];
|
|
103
|
+
const cmd = [...server.command];
|
|
104
|
+
if (name === 'serena') cmd.splice(cmd.indexOf('start-mcp-server') + 1, 0, '--context', server.context['claude-code']);
|
|
105
|
+
commands.push({
|
|
106
|
+
tool: name,
|
|
107
|
+
desc: `${name} MCP server (user scope)`,
|
|
108
|
+
run: [['claude', 'mcp', 'add', '--scope', 'user', name, '--', ...cmd]],
|
|
109
|
+
undo: [['claude', 'mcp', 'remove', '--scope', 'user', name]],
|
|
110
|
+
skipIfOutput: { cmd: ['claude', 'mcp', 'get', name], ok: true },
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (tools.includes('caveman')) {
|
|
114
|
+
commands.push({
|
|
115
|
+
tool: 'caveman',
|
|
116
|
+
desc: 'Caveman skills for Claude Code',
|
|
117
|
+
run: [['npx', '-y', skillsCli(), 'add', skillSource('caveman'), '--skill', 'caveman', 'caveman-compress', 'caveman-stats', '-a', 'claude-code', '-g', '-y']],
|
|
118
|
+
undo: [['npx', '-y', skillsCli(), 'remove', 'caveman', 'caveman-compress', 'caveman-stats', '-a', 'claude-code', '-g', '-y']],
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return { actions, commands };
|
|
122
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// GitHub Copilot CLI adapter. Paths and keys confirmed on copilot 1.0.105 in CI.
|
|
2
|
+
// Copilot has no rule import, so the rendered rules go in a marked block.
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { OWNED_MARK } from '../fsops.mjs';
|
|
6
|
+
import { tierFor, modelFor } from '../render.mjs';
|
|
7
|
+
import { envDir } from '../system.mjs';
|
|
8
|
+
import { localServer } from './opencode-v2.mjs';
|
|
9
|
+
import { skillSource, skillsCli } from '../pins.mjs';
|
|
10
|
+
import { toolEnv } from '../node-runtime.mjs';
|
|
11
|
+
|
|
12
|
+
const CONTEXT_MODE_SCRIPT = fileURLToPath(new URL('../../copilot-context-mode.mjs', import.meta.url));
|
|
13
|
+
|
|
14
|
+
const TOOLS = {
|
|
15
|
+
'read-only': ['read', 'search'],
|
|
16
|
+
'git-read': ['read', 'search', 'execute'],
|
|
17
|
+
'read-write': null,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Web tools are dropped when other outbound calls are off.
|
|
21
|
+
export function renderCopilotAgent(agent, profile, web) {
|
|
22
|
+
const tier = tierFor(profile, agent.name, agent.tier);
|
|
23
|
+
const model = modelFor(profile, tier)?.model.replace('github-copilot/', '');
|
|
24
|
+
const tools = TOOLS[agent.access] && [...TOOLS[agent.access], ...(agent.name === 'research' && web ? ['web'] : [])];
|
|
25
|
+
const lines = ['---', `# ${OWNED_MARK} (tier: ${tier})`, `name: ${agent.name}`, `description: ${agent.description}`];
|
|
26
|
+
if (model) lines.push(`model: ${model}`);
|
|
27
|
+
if (tools) lines.push(`tools: ${JSON.stringify(tools)}`);
|
|
28
|
+
lines.push('---', '', agent.body, '');
|
|
29
|
+
return lines.join('\n');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const skills = (tool, desc, repo, names) => ({
|
|
33
|
+
tool,
|
|
34
|
+
desc,
|
|
35
|
+
run: [['npx', '-y', skillsCli(), 'add', repo, '--skill', ...names, '-a', 'github-copilot', '-g', '-y']],
|
|
36
|
+
// Without -a: `remove -a` keeps ~/.agents/skills while another detected agent may share that folder.
|
|
37
|
+
undo: [['npx', '-y', skillsCli(), 'remove', ...names, '-g', '-y']],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export function copilotAdapter({ home, core, profile, opts, rules, adhdCommand }) {
|
|
41
|
+
const dir = envDir(home, 'COPILOT_HOME', path.join(home, '.copilot'));
|
|
42
|
+
const tools = opts.tools;
|
|
43
|
+
const actions = [{ kind: 'block', path: path.join(dir, 'copilot-instructions.md'), body: rules }];
|
|
44
|
+
const commands = [];
|
|
45
|
+
|
|
46
|
+
for (const agent of core.agents) {
|
|
47
|
+
actions.push({ kind: 'file', path: path.join(dir, 'agents', `${agent.name}.agent.md`), content: renderCopilotAgent(agent, profile, opts.network.outbound !== 'off') });
|
|
48
|
+
}
|
|
49
|
+
const edits = [];
|
|
50
|
+
for (const name of ['serena', 'playwright', 'playwright-extension'].filter((t) => tools.includes(t))) {
|
|
51
|
+
const [command, ...args] = localServer(core, name).command;
|
|
52
|
+
edits.push({ path: ['mcpServers', name], value: { type: 'local', command, args, tools: ['*'] }, mode: 'setIfAbsent' });
|
|
53
|
+
}
|
|
54
|
+
if (edits.length) actions.push({ kind: 'json', path: path.join(dir, 'mcp-config.json'), edits, keepEmpty: [['mcpServers']] });
|
|
55
|
+
if (opts.network.autoUpdate === 'off') {
|
|
56
|
+
actions.push({ kind: 'json', path: path.join(dir, 'settings.json'), edits: [{ path: ['autoUpdate'], value: false, mode: 'set' }] });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (tools.includes('rtk')) {
|
|
60
|
+
commands.push({ tool: 'rtk', desc: 'RTK hook for Copilot CLI', run: [['rtk', 'init', '-g', '--copilot']], undo: [['rtk', 'init', '-g', '--copilot', '--uninstall']] });
|
|
61
|
+
}
|
|
62
|
+
if (tools.includes('context-mode')) {
|
|
63
|
+
// Only the MCP server (`copilot mcp add`, which writes mcp-config.json itself); the npm package comes from the prerequisite step.
|
|
64
|
+
commands.push({
|
|
65
|
+
tool: 'context-mode',
|
|
66
|
+
desc: 'Context Mode MCP server for Copilot CLI',
|
|
67
|
+
run: [[opts.toolNode?.node ?? 'node', CONTEXT_MODE_SCRIPT]],
|
|
68
|
+
undo: [['copilot', 'mcp', 'remove', 'context-mode']],
|
|
69
|
+
// The script registers process.execPath, so it must run on the tool's Node and look for the package in that Node's prefix.
|
|
70
|
+
...(opts.toolNode && { env: { ...toolEnv(opts.toolNode), LEAN_CONTEXT_MODE_DIR: path.join(opts.toolNode.modules, 'context-mode') } }),
|
|
71
|
+
});
|
|
72
|
+
console.log('Context Mode hooks and skills for Copilot CLI are not installed: run `context-mode setup --print copilot-cli` and follow it.');
|
|
73
|
+
}
|
|
74
|
+
if (tools.includes('caveman')) {
|
|
75
|
+
commands.push(skills('caveman', 'Caveman skills for Copilot CLI', skillSource('caveman'), ['caveman', 'caveman-compress', 'caveman-stats']));
|
|
76
|
+
}
|
|
77
|
+
if (tools.includes('i-have-adhd')) {
|
|
78
|
+
commands.push(skills('i-have-adhd', 'i-have-adhd skill for Copilot CLI', skillSource('i-have-adhd'), ['i-have-adhd']), adhdCommand);
|
|
79
|
+
}
|
|
80
|
+
return { actions, commands };
|
|
81
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Cursor adapter (IDE and the `agent` CLI). Cursor keeps user rules in its settings UI only,
|
|
2
|
+
// so global rules are not written here; `--project` puts them in the repo's AGENTS.md.
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { OWNED_MARK } from '../fsops.mjs';
|
|
5
|
+
import { localServer, mcpEdit } from './opencode-v2.mjs';
|
|
6
|
+
import { hasProxy } from '../network.mjs';
|
|
7
|
+
import { skillSource, skillsCli } from '../pins.mjs';
|
|
8
|
+
|
|
9
|
+
// Model IDs differ from every profile, so subagents inherit the chat model.
|
|
10
|
+
export function renderCursorAgent(agent) {
|
|
11
|
+
return [
|
|
12
|
+
'---',
|
|
13
|
+
`# ${OWNED_MARK} (tier: ${agent.tier})`,
|
|
14
|
+
`name: ${agent.name}`,
|
|
15
|
+
`description: ${agent.description}`,
|
|
16
|
+
'model: inherit',
|
|
17
|
+
`readonly: ${agent.access !== 'read-write'}`,
|
|
18
|
+
'---',
|
|
19
|
+
'',
|
|
20
|
+
agent.body,
|
|
21
|
+
'',
|
|
22
|
+
].join('\n');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// `mcpServers` entries for a Cursor mcp.json, user or project.
|
|
26
|
+
export function cursorServers(core, tools) {
|
|
27
|
+
return ['serena', 'playwright', 'playwright-extension', 'context-mode'].filter((t) => tools.includes(t)).map((name) => {
|
|
28
|
+
return mcpEdit(['mcpServers', name], ([command, ...args]) => ({ command, args }), localServer(core, name).command, core.mcp[name].legacy);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const skills = (tool, desc, repo, names) => ({
|
|
33
|
+
tool,
|
|
34
|
+
desc,
|
|
35
|
+
run: [['npx', '-y', skillsCli(), 'add', repo, '--skill', ...names, '-a', 'cursor', '-g', '-y']],
|
|
36
|
+
// Without -a: `remove -a` keeps ~/.agents/skills while another detected agent may share that folder.
|
|
37
|
+
undo: [['npx', '-y', skillsCli(), 'remove', ...names, '-g', '-y']],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export function cursorAdapter({ home, core, opts, adhdCommand }) {
|
|
41
|
+
const dir = path.join(home, '.cursor');
|
|
42
|
+
const tools = opts.tools;
|
|
43
|
+
const actions = core.agents.map((agent) => ({ kind: 'file', path: path.join(dir, 'agents', `${agent.name}.md`), content: renderCursorAgent(agent) }));
|
|
44
|
+
const commands = [];
|
|
45
|
+
const edits = cursorServers(core, tools);
|
|
46
|
+
if (edits.length) actions.push({ kind: 'json', path: path.join(dir, 'mcp.json'), edits });
|
|
47
|
+
// Proxies such as Zscaler break the agent's HTTP/2 stream (#25). Only the flag is written, never a proxy value.
|
|
48
|
+
if (hasProxy()) actions.push({ kind: 'json', path: path.join(dir, 'cli-config.json'), edits: [{ path: ['network', 'useHttp1ForAgent'], value: true, mode: 'setIfAbsent' }] });
|
|
49
|
+
|
|
50
|
+
if (tools.includes('rtk')) {
|
|
51
|
+
commands.push({ tool: 'rtk', desc: 'RTK hook for Cursor', run: [['rtk', 'init', '-g', '--agent', 'cursor']], undo: [['rtk', 'init', '-g', '--agent', 'cursor', '--uninstall']] });
|
|
52
|
+
}
|
|
53
|
+
if (tools.includes('caveman')) {
|
|
54
|
+
commands.push(skills('caveman', 'Caveman skills for Cursor', skillSource('caveman'), ['caveman', 'caveman-compress', 'caveman-stats']));
|
|
55
|
+
}
|
|
56
|
+
if (tools.includes('i-have-adhd')) {
|
|
57
|
+
commands.push(skills('i-have-adhd', 'i-have-adhd skill for Cursor', skillSource('i-have-adhd'), ['i-have-adhd']), adhdCommand);
|
|
58
|
+
}
|
|
59
|
+
return { actions, commands };
|
|
60
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// OpenCode 1.x adapter (>=1.18.29). Keys checked against the 1.19.0 config schema; files
|
|
2
|
+
// and commands are shared with the 2.x adapter, only config keys differ.
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { configPath, localServer, opencodeShared, profileEdits, shellEdit } from './opencode-v2.mjs';
|
|
5
|
+
import { OWNED_MARK } from '../fsops.mjs';
|
|
6
|
+
import { configHome } from '../system.mjs';
|
|
7
|
+
import { npmSpec } from '../pins.mjs';
|
|
8
|
+
|
|
9
|
+
// OpenCode 1.19's TUI runs server plugins in a Bun worker and never calls the factory in Orca's managed
|
|
10
|
+
// plugins/orca-opencode-status.js, so Orca shows no status. Loading it from a file under another name
|
|
11
|
+
// fixes that (issue #78). Worker only: headless `opencode run` already loads the managed file.
|
|
12
|
+
const ORCA_SHIM = `// ${OWNED_MARK}
|
|
13
|
+
// Lets Orca's status plugin run in OpenCode 1.x's TUI worker (lean-agents#78).
|
|
14
|
+
export const LeanOrcaStatusShim = async (ctx) => {
|
|
15
|
+
if (typeof Bun === 'undefined' || Bun.isMainThread) return {};
|
|
16
|
+
try {
|
|
17
|
+
const mod = await import('./orca-opencode-status.js');
|
|
18
|
+
// Orca's default export is the factory (ORCA_OPENCODE_PLUGIN_API=v1) or an { id, server } object.
|
|
19
|
+
const factory = typeof mod.default === 'function' ? mod.default : mod.default?.server ?? mod.OrcaOpenCodeStatusPlugin;
|
|
20
|
+
return (await factory?.(ctx)) ?? {};
|
|
21
|
+
} catch {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
// Windows only: the bug is seen on the Windows work PC and not reproduced on Linux or macOS in CI, where the
|
|
28
|
+
// shim would run Orca's plugin a second time.
|
|
29
|
+
export function orcaShimActions({ dir, terminals, platform = process.platform }) {
|
|
30
|
+
if (platform !== 'win32' || !terminals?.includes('orca')) return [];
|
|
31
|
+
return [{ kind: 'file', path: path.join(dir, 'plugins', 'lean-orca-status-shim.js'), content: ORCA_SHIM }];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function opencodeV1Adapter({ home, core, profile, opts, rulesPath }) {
|
|
35
|
+
const dir = path.join(configHome(home), 'opencode');
|
|
36
|
+
const tools = opts.tools;
|
|
37
|
+
const { actions, commands } = opencodeShared({ home, dir, core, profile, opts });
|
|
38
|
+
const edits = [
|
|
39
|
+
{ path: ['$schema'], value: 'https://opencode.ai/config.json', mode: 'setIfAbsent' },
|
|
40
|
+
{ path: ['instructions'], value: rulesPath, mode: 'arrayAdd' },
|
|
41
|
+
{ path: ['default_agent'], value: 'plan', mode: 'setIfAbsent' },
|
|
42
|
+
{ path: ['compaction', 'auto'], value: true, mode: 'setIfAbsent' },
|
|
43
|
+
{ path: ['compaction', 'reserved'], value: 40000, mode: 'setIfAbsent' },
|
|
44
|
+
...profileEdits(profile, 'agent'),
|
|
45
|
+
];
|
|
46
|
+
const shell = shellEdit(opts);
|
|
47
|
+
if (shell) edits.push(shell);
|
|
48
|
+
|
|
49
|
+
for (const name of ['serena', 'playwright', 'playwright-extension']) {
|
|
50
|
+
if (tools.includes(name)) edits.push({ path: ['mcp', name], value: localServer(core, name), mode: 'setIfAbsent' });
|
|
51
|
+
}
|
|
52
|
+
// Context Mode is plugin-only here: plugin plus MCP breaks OpenCode tool registration.
|
|
53
|
+
if (tools.includes('context-mode')) {
|
|
54
|
+
edits.push({ path: ['plugin'], value: npmSpec('context-mode'), mode: 'arrayAdd', legacy: ['context-mode'] });
|
|
55
|
+
commands.push({
|
|
56
|
+
tool: 'context-mode',
|
|
57
|
+
desc: 'Context Mode package for OpenCode',
|
|
58
|
+
run: [['npm', 'install', '-g', npmSpec('context-mode')]],
|
|
59
|
+
undo: [['npm', 'uninstall', '-g', 'context-mode']],
|
|
60
|
+
skipIfOutput: { cmd: ['npm', 'ls', '-g', 'context-mode'], ok: true },
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (opts.terminals?.includes('warp')) edits.push({ path: ['plugin'], value: npmSpec('warp-opencode'), mode: 'arrayAdd', legacy: ['@warp-dot-dev/opencode-warp', '@warp-dot-dev/opencode-warp@0.1.7'] });
|
|
64
|
+
actions.push(...orcaShimActions({ dir, terminals: opts.terminals, platform: opts.platform }));
|
|
65
|
+
if (tools.includes('ponytail')) edits.push({ path: ['plugin'], value: npmSpec('ponytail'), mode: 'arrayAdd', legacy: ['@dietrichgebert/ponytail'] });
|
|
66
|
+
if (tools.includes('dcp')) {
|
|
67
|
+
edits.push({ path: ['plugin'], value: npmSpec('opencode-dcp'), mode: 'arrayAdd' });
|
|
68
|
+
const contextWindow = profile?.context_window ?? 200000;
|
|
69
|
+
actions.push({
|
|
70
|
+
kind: 'json',
|
|
71
|
+
path: path.join(dir, 'dcp.jsonc'),
|
|
72
|
+
edits: [
|
|
73
|
+
{ path: ['$schema'], value: 'https://raw.githubusercontent.com/Opencode-DCP/opencode-dynamic-context-pruning/master/dcp.schema.json', mode: 'setIfAbsent' },
|
|
74
|
+
{ path: ['compress', 'minContextLimit'], value: Math.round(contextWindow * 0.5), mode: 'setIfAbsent' },
|
|
75
|
+
{ path: ['compress', 'maxContextLimit'], value: Math.round(contextWindow * 0.8), mode: 'setIfAbsent' },
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const net = opts.network;
|
|
80
|
+
if (net.outbound === 'off') edits.push({ path: ['share'], value: 'disabled', mode: 'set' });
|
|
81
|
+
if (net.autoUpdate === 'off') edits.push({ path: ['autoupdate'], value: false, mode: 'set' });
|
|
82
|
+
if (net.telemetry === 'off') edits.push({ path: ['experimental', 'openTelemetry'], value: false, mode: 'set' });
|
|
83
|
+
if (net.outbound === 'off' && profile?.provider !== 'opencode') edits.push({ path: ['disabled_providers'], value: 'opencode', mode: 'arrayAdd' });
|
|
84
|
+
actions.push({ kind: 'json', path: configPath(dir), edits });
|
|
85
|
+
return { actions, commands };
|
|
86
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// OpenCode 2.x adapter. Uses the native 2.x keys (agents, plugins, update, policies,
|
|
2
|
+
// mcp.servers), confirmed against `opencode debug config` on OpenCode 2.2 in CI.
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
|
+
import { OWNED_MARK } from '../fsops.mjs';
|
|
8
|
+
import { tierFor, modelFor } from '../render.mjs';
|
|
9
|
+
import { configHome } from '../system.mjs';
|
|
10
|
+
import { gitBashPath } from '../terminals.mjs';
|
|
11
|
+
import { PINS, npmSpec, skillSource, skillsCli } from '../pins.mjs';
|
|
12
|
+
|
|
13
|
+
const PERMISSIONS = {
|
|
14
|
+
'read-only': [' edit: deny', ' bash: deny'],
|
|
15
|
+
'git-read': [' edit: deny', ' bash:', ' "*": deny', ' "git diff*": allow', ' "git log*": allow', ' "git show*": allow', ' "git status*": allow'],
|
|
16
|
+
'read-write': [],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function renderOpenCodeAgent(agent, profile) {
|
|
20
|
+
const tier = tierFor(profile, agent.name, agent.tier);
|
|
21
|
+
const m = modelFor(profile, tier);
|
|
22
|
+
const lines = ['---', `# ${OWNED_MARK} (tier: ${tier})`, `description: ${agent.description}`, 'mode: subagent'];
|
|
23
|
+
if (m?.model) lines.push(`model: ${m.model}`);
|
|
24
|
+
for (const [k, v] of Object.entries(m?.options ?? {})) lines.push(`${k}: ${v}`);
|
|
25
|
+
const perms = [...PERMISSIONS[agent.access]];
|
|
26
|
+
if (agent.name === 'research') perms.push(' webfetch: allow');
|
|
27
|
+
if (perms.length) lines.push('permission:', ...perms);
|
|
28
|
+
lines.push('---', '', agent.body, '');
|
|
29
|
+
return lines.join('\n');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function configPath(dir) {
|
|
33
|
+
for (const f of ['opencode.jsonc', 'opencode.json']) {
|
|
34
|
+
if (fs.existsSync(path.join(dir, f))) return path.join(dir, f);
|
|
35
|
+
}
|
|
36
|
+
return path.join(dir, 'opencode.jsonc');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function localServer(core, name) {
|
|
40
|
+
const server = core.mcp[name];
|
|
41
|
+
const command = [...server.command];
|
|
42
|
+
if (name === 'serena') command.splice(command.indexOf('start-mcp-server') + 1, 0, '--context', server.context.default);
|
|
43
|
+
return { type: 'local', command, enabled: true };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// MCP entry edit. `shape` turns a command array into this agent's entry. A server with `legacy` commands in core/mcp.json
|
|
47
|
+
// (Context Mode: other versions, with or without `server`, npx or an nvm Node; `*` is a wildcard) has those entries replaced
|
|
48
|
+
// by a rerun, so the npx and absolute forms flip either way. Anything else the user has is kept.
|
|
49
|
+
export function mcpEdit(path, shape, command, legacy) {
|
|
50
|
+
const value = shape(command);
|
|
51
|
+
return legacy ? { path, value, mode: 'upgradeIf', legacy: legacy.map(shape) } : { path, value, mode: 'setIfAbsent' };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Windows only, and only when Git Bash is actually found (#124 follow-up, proven in `real-opencode-shell`
|
|
55
|
+
// CI for both majors: setting `shell` to an absolute Git Bash path makes the bash/shell tool run there,
|
|
56
|
+
// PATH or not). `setIfAbsent` never overwrites a `shell` the user already set. `opts.shell === 'default'`
|
|
57
|
+
// opts out (`--shell default`). `opts.platform`/`opts.env` let tests fake the OS without one.
|
|
58
|
+
export function shellEdit(opts) {
|
|
59
|
+
if (opts.shell === 'default') return null;
|
|
60
|
+
const bash = gitBashPath({ platform: opts.platform ?? process.platform, env: opts.env ?? process.env });
|
|
61
|
+
return bash ? { path: ['shell'], value: bash, mode: 'setIfAbsent' } : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function profileEdits(profile, agentsKey) {
|
|
65
|
+
if (!profile) return [];
|
|
66
|
+
const edits = [];
|
|
67
|
+
if (profile.main_model) edits.push({ path: ['model'], value: profile.main_model, mode: 'setIfAbsent' });
|
|
68
|
+
for (const [agent, tier] of Object.entries(profile.primary ?? {})) {
|
|
69
|
+
const m = modelFor(profile, tier);
|
|
70
|
+
if (!m) continue;
|
|
71
|
+
edits.push({ path: [agentsKey, agent, 'model'], value: m.model, mode: 'setIfAbsent' });
|
|
72
|
+
for (const [k, v] of Object.entries(m.options ?? {})) edits.push({ path: [agentsKey, agent, k], value: v, mode: 'setIfAbsent' });
|
|
73
|
+
}
|
|
74
|
+
return edits;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Read at import, before isolate() points HOME and USERPROFILE at --home.
|
|
78
|
+
const REAL_HOME = os.homedir();
|
|
79
|
+
|
|
80
|
+
function ponytailConfig(home) {
|
|
81
|
+
if (process.platform !== 'win32') return path.join(configHome(home), 'ponytail', 'config.json');
|
|
82
|
+
// Only the real home may use %APPDATA%: --home must keep every write inside the temp dir.
|
|
83
|
+
const appData = home === REAL_HOME && process.env.APPDATA ? process.env.APPDATA : path.join(home, 'AppData', 'Roaming');
|
|
84
|
+
return path.join(appData, 'ponytail', 'config.json');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Everything that is the same on OpenCode 1.x and 2.x: files and commands, not config keys.
|
|
88
|
+
export function opencodeShared({ home, dir, core, profile, opts, v2 = false }) {
|
|
89
|
+
const tools = opts.tools;
|
|
90
|
+
const actions = [];
|
|
91
|
+
const commands = [];
|
|
92
|
+
if (tools.includes('ponytail')) {
|
|
93
|
+
actions.push({ kind: 'json', path: ponytailConfig(home), edits: [{ path: ['defaultMode'], value: opts.ponytailMode, mode: 'setIfAbsent' }] });
|
|
94
|
+
}
|
|
95
|
+
if (tools.includes('copilot-usage')) {
|
|
96
|
+
// Own folder, so the hand-made copilot-usage-tui is never touched. 1.x loads it through a tui.json entry; 2.x discovers
|
|
97
|
+
// plugins/<dir>/tui.js by itself (docs: opencode.ai/docs/build/plugins), so there is no config entry there.
|
|
98
|
+
const file = path.join(dir, 'plugins', 'lean-copilot-usage', 'tui.js');
|
|
99
|
+
const source = fs.readFileSync(fileURLToPath(new URL('../../../core/copilot-usage-tui.js', import.meta.url)), 'utf8');
|
|
100
|
+
actions.push({ kind: 'file', path: file, content: `// ${OWNED_MARK}\n${source}` });
|
|
101
|
+
if (!v2) actions.push({ kind: 'json', path: path.join(dir, 'tui.json'), edits: [{ path: ['plugin'], value: pathToFileURL(file).href, mode: 'arrayAdd' }] });
|
|
102
|
+
}
|
|
103
|
+
for (const agent of core.agents) {
|
|
104
|
+
actions.push({ kind: 'file', path: path.join(dir, 'agents', `${agent.name}.md`), content: renderOpenCodeAgent(agent, profile) });
|
|
105
|
+
}
|
|
106
|
+
if (tools.includes('rtk')) {
|
|
107
|
+
commands.push({ tool: 'rtk', desc: 'RTK plugin for OpenCode', run: [['rtk', 'init', '-g', '--opencode']], undo: [['rtk', 'init', '-g', '--opencode', '--uninstall']] });
|
|
108
|
+
}
|
|
109
|
+
if (tools.includes('i-have-adhd')) {
|
|
110
|
+
const vendor = path.join(dir, 'vendor', 'i-have-adhd');
|
|
111
|
+
commands.push({
|
|
112
|
+
tool: 'i-have-adhd',
|
|
113
|
+
desc: 'i-have-adhd checkout for OpenCode',
|
|
114
|
+
// The tag must still point at the pinned commit; a moved tag removes the checkout and fails the command.
|
|
115
|
+
run: [['git', 'clone', '--depth', '1', '--branch', PINS['i-have-adhd'].version, 'https://github.com/ayghri/i-have-adhd', vendor],
|
|
116
|
+
[process.execPath, fileURLToPath(new URL('../verify-commit.mjs', import.meta.url)), vendor, PINS['i-have-adhd'].sha]],
|
|
117
|
+
undo: [['node', '-e', 'require("fs").rmSync(process.argv[1], { recursive: true, force: true })', vendor]],
|
|
118
|
+
skipIfExists: vendor,
|
|
119
|
+
});
|
|
120
|
+
actions.push({
|
|
121
|
+
kind: 'file',
|
|
122
|
+
path: path.join(dir, 'plugins', 'i-have-adhd.ts'),
|
|
123
|
+
content: `// ${OWNED_MARK}\nexport { default } from '../vendor/i-have-adhd/.opencode/plugins/i-have-adhd.mjs';\n`,
|
|
124
|
+
});
|
|
125
|
+
if (opts.adhdAlways) actions.push({ kind: 'file', path: path.join(dir, '.i-have-adhd-always'), content: '', force: true });
|
|
126
|
+
}
|
|
127
|
+
if (tools.includes('caveman')) {
|
|
128
|
+
commands.push({
|
|
129
|
+
tool: 'caveman',
|
|
130
|
+
desc: 'Caveman skills for OpenCode',
|
|
131
|
+
run: [['npx', '-y', skillsCli(), 'add', skillSource('caveman'), '--skill', 'caveman', 'caveman-compress', 'caveman-stats', '-a', 'opencode', '-g', '-y']],
|
|
132
|
+
// Without -a: `remove -a` keeps ~/.agents/skills while another detected agent may share that folder.
|
|
133
|
+
undo: [['npx', '-y', skillsCli(), 'remove', 'caveman', 'caveman-compress', 'caveman-stats', '-g', '-y']],
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return { actions, commands };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function opencodeV2Adapter({ home, core, profile, opts, rulesPath }) {
|
|
140
|
+
const dir = path.join(configHome(home), 'opencode');
|
|
141
|
+
const tools = opts.tools;
|
|
142
|
+
const { actions, commands } = opencodeShared({ home, dir, core, profile, opts, v2: true });
|
|
143
|
+
const edits = [
|
|
144
|
+
{ path: ['$schema'], value: 'https://opencode.ai/config.json', mode: 'setIfAbsent' },
|
|
145
|
+
{ path: ['instructions'], value: rulesPath, mode: 'arrayAdd' },
|
|
146
|
+
{ path: ['default_agent'], value: 'plan', mode: 'setIfAbsent' },
|
|
147
|
+
{ path: ['compaction', 'auto'], value: true, mode: 'setIfAbsent' },
|
|
148
|
+
{ path: ['compaction', 'buffer'], value: 40000, mode: 'setIfAbsent' },
|
|
149
|
+
...profileEdits(profile, 'agents'),
|
|
150
|
+
];
|
|
151
|
+
const shell = shellEdit(opts);
|
|
152
|
+
if (shell) edits.push(shell);
|
|
153
|
+
|
|
154
|
+
for (const name of ['context-mode', 'serena', 'playwright', 'playwright-extension']) {
|
|
155
|
+
if (tools.includes(name)) edits.push(mcpEdit(['mcp', 'servers', name], (command) => ({ type: 'local', command, enabled: true }), localServer(core, name).command, core.mcp[name].legacy));
|
|
156
|
+
}
|
|
157
|
+
if (tools.includes('ponytail')) edits.push({ path: ['plugins'], value: npmSpec('ponytail'), mode: 'arrayAdd', legacy: ['@dietrichgebert/ponytail'] });
|
|
158
|
+
if (opts.terminals?.includes('warp')) edits.push({ path: ['plugins'], value: npmSpec('warp-opencode'), mode: 'arrayAdd', legacy: ['@warp-dot-dev/opencode-warp'] });
|
|
159
|
+
if (opts.network.outbound === 'off') edits.push({ path: ['share'], value: 'disabled', mode: 'set' });
|
|
160
|
+
if (opts.network.autoUpdate === 'off') edits.push({ path: ['update'], value: 'disable', mode: 'set' });
|
|
161
|
+
if (opts.network.outbound === 'off') {
|
|
162
|
+
if (profile?.provider !== 'opencode') {
|
|
163
|
+
edits.push({ path: ['policies'], value: { effect: 'deny', action: 'provider.use', resource: 'opencode' }, mode: 'arrayAdd' });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
actions.push({ kind: 'json', path: configPath(dir), edits });
|
|
167
|
+
return { actions, commands };
|
|
168
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// VS Code Copilot adapter. VS Code reads the same user rules, agents and skills as Copilot CLI
|
|
2
|
+
// (~/.copilot, ~/.agents/skills), so those are skipped when copilot-cli is installed too.
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { configHome, envDir } from '../system.mjs';
|
|
6
|
+
import { localServer, mcpEdit } from './opencode-v2.mjs';
|
|
7
|
+
import { renderCopilotAgent, skills } from './copilot-cli.mjs';
|
|
8
|
+
import { skillSource } from '../pins.mjs';
|
|
9
|
+
|
|
10
|
+
// Read at import, before isolate() points HOME and USERPROFILE at --home.
|
|
11
|
+
const REAL_HOME = os.homedir();
|
|
12
|
+
|
|
13
|
+
export function vscodeUserDir(home) {
|
|
14
|
+
if (process.platform === 'darwin') return path.join(home, 'Library', 'Application Support', 'Code', 'User');
|
|
15
|
+
if (process.platform !== 'win32') return path.join(configHome(home), 'Code', 'User');
|
|
16
|
+
// Only the real home may use %APPDATA%: --home must keep every write inside the temp dir.
|
|
17
|
+
const appData = home === REAL_HOME && process.env.APPDATA ? process.env.APPDATA : path.join(home, 'AppData', 'Roaming');
|
|
18
|
+
return path.join(appData, 'Code', 'User');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// `servers` entries for a VS Code mcp.json, user or workspace.
|
|
22
|
+
export function vscodeServers(core, tools) {
|
|
23
|
+
return ['serena', 'playwright', 'playwright-extension', 'context-mode'].filter((t) => tools.includes(t)).map((name) => {
|
|
24
|
+
return mcpEdit(['servers', name], ([command, ...args]) => ({ type: 'stdio', command, args }), localServer(core, name).command, core.mcp[name].legacy);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function vscodeCopilotAdapter({ home, core, profile, opts, rules, adhdCommand }) {
|
|
29
|
+
const tools = opts.tools;
|
|
30
|
+
const user = vscodeUserDir(home);
|
|
31
|
+
const actions = [];
|
|
32
|
+
const commands = [];
|
|
33
|
+
if (!opts.agents.includes('copilot-cli')) {
|
|
34
|
+
const dir = envDir(home, 'COPILOT_HOME', path.join(home, '.copilot'));
|
|
35
|
+
actions.push({ kind: 'block', path: path.join(dir, 'copilot-instructions.md'), body: rules });
|
|
36
|
+
for (const agent of core.agents) {
|
|
37
|
+
actions.push({ kind: 'file', path: path.join(dir, 'agents', `${agent.name}.agent.md`), content: renderCopilotAgent(agent, profile, opts.network.outbound !== 'off') });
|
|
38
|
+
}
|
|
39
|
+
if (tools.includes('caveman')) {
|
|
40
|
+
commands.push(skills('caveman', 'Caveman skills for VS Code Copilot', skillSource('caveman'), ['caveman', 'caveman-compress', 'caveman-stats']));
|
|
41
|
+
}
|
|
42
|
+
if (tools.includes('i-have-adhd')) {
|
|
43
|
+
commands.push(skills('i-have-adhd', 'i-have-adhd skill for VS Code Copilot', skillSource('i-have-adhd'), ['i-have-adhd']), adhdCommand);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const edits = vscodeServers(core, tools);
|
|
47
|
+
if (edits.length) actions.push({ kind: 'json', path: path.join(user, 'mcp.json'), edits });
|
|
48
|
+
if (opts.privacy === 'strict') {
|
|
49
|
+
actions.push({
|
|
50
|
+
kind: 'json',
|
|
51
|
+
path: path.join(user, 'settings.json'),
|
|
52
|
+
edits: [{ path: ['telemetry.telemetryLevel'], value: 'off', mode: 'set' }, { path: ['update.mode'], value: 'none', mode: 'set' }],
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return { actions, commands };
|
|
56
|
+
}
|