lean-agents 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/CHANGELOG.md +407 -0
  2. package/LICENSE +21 -0
  3. package/README.es.md +560 -0
  4. package/README.md +559 -2
  5. package/core/AGENTS.es.md +60 -0
  6. package/core/AGENTS.md +60 -0
  7. package/core/README.md +8 -0
  8. package/core/agents/debug.md +14 -0
  9. package/core/agents/explore.md +13 -0
  10. package/core/agents/planner.md +14 -0
  11. package/core/agents/research.md +13 -0
  12. package/core/agents/review.md +13 -0
  13. package/core/copilot-usage-tui.js +189 -0
  14. package/core/mcp.json +38 -0
  15. package/core/pins.json +39 -0
  16. package/core/tiers.json +4 -0
  17. package/node_modules/@clack/core/LICENSE +9 -0
  18. package/node_modules/@clack/core/README.md +22 -0
  19. package/node_modules/@clack/core/dist/index.d.mts +503 -0
  20. package/node_modules/@clack/core/dist/index.mjs +1003 -0
  21. package/node_modules/@clack/core/package.json +63 -0
  22. package/node_modules/@clack/prompts/LICENSE +9 -0
  23. package/node_modules/@clack/prompts/README.md +396 -0
  24. package/node_modules/@clack/prompts/dist/index.d.mts +949 -0
  25. package/node_modules/@clack/prompts/dist/index.mjs +1423 -0
  26. package/node_modules/@clack/prompts/package.json +67 -0
  27. package/node_modules/fast-string-truncated-width/dist/index.d.ts +4 -0
  28. package/node_modules/fast-string-truncated-width/dist/index.js +111 -0
  29. package/node_modules/fast-string-truncated-width/dist/types.d.ts +19 -0
  30. package/node_modules/fast-string-truncated-width/dist/types.js +2 -0
  31. package/node_modules/fast-string-truncated-width/dist/utils.d.ts +4 -0
  32. package/node_modules/fast-string-truncated-width/dist/utils.js +20 -0
  33. package/node_modules/fast-string-truncated-width/license +21 -0
  34. package/node_modules/fast-string-truncated-width/package.json +35 -0
  35. package/node_modules/fast-string-truncated-width/readme.md +59 -0
  36. package/node_modules/fast-string-width/dist/index.d.ts +4 -0
  37. package/node_modules/fast-string-width/dist/index.js +14 -0
  38. package/node_modules/fast-string-width/license +21 -0
  39. package/node_modules/fast-string-width/package.json +34 -0
  40. package/node_modules/fast-string-width/readme.md +42 -0
  41. package/node_modules/fast-wrap-ansi/LICENSE +23 -0
  42. package/node_modules/fast-wrap-ansi/README.md +26 -0
  43. package/node_modules/fast-wrap-ansi/lib/main.d.ts +6 -0
  44. package/node_modules/fast-wrap-ansi/lib/main.js +218 -0
  45. package/node_modules/fast-wrap-ansi/package.json +51 -0
  46. package/node_modules/jsonc-parser/CHANGELOG.md +76 -0
  47. package/node_modules/jsonc-parser/LICENSE.md +21 -0
  48. package/node_modules/jsonc-parser/README.md +364 -0
  49. package/node_modules/jsonc-parser/SECURITY.md +41 -0
  50. package/node_modules/jsonc-parser/lib/esm/impl/edit.js +185 -0
  51. package/node_modules/jsonc-parser/lib/esm/impl/format.js +261 -0
  52. package/node_modules/jsonc-parser/lib/esm/impl/parser.js +659 -0
  53. package/node_modules/jsonc-parser/lib/esm/impl/scanner.js +443 -0
  54. package/node_modules/jsonc-parser/lib/esm/impl/string-intern.js +29 -0
  55. package/node_modules/jsonc-parser/lib/esm/main.d.ts +351 -0
  56. package/node_modules/jsonc-parser/lib/esm/main.js +178 -0
  57. package/node_modules/jsonc-parser/lib/umd/impl/edit.js +201 -0
  58. package/node_modules/jsonc-parser/lib/umd/impl/format.js +275 -0
  59. package/node_modules/jsonc-parser/lib/umd/impl/parser.js +682 -0
  60. package/node_modules/jsonc-parser/lib/umd/impl/scanner.js +456 -0
  61. package/node_modules/jsonc-parser/lib/umd/impl/string-intern.js +42 -0
  62. package/node_modules/jsonc-parser/lib/umd/main.d.ts +351 -0
  63. package/node_modules/jsonc-parser/lib/umd/main.js +194 -0
  64. package/node_modules/jsonc-parser/package.json +37 -0
  65. package/node_modules/sisteransi/license +21 -0
  66. package/node_modules/sisteransi/package.json +34 -0
  67. package/node_modules/sisteransi/readme.md +113 -0
  68. package/node_modules/sisteransi/src/index.js +58 -0
  69. package/node_modules/sisteransi/src/sisteransi.d.ts +35 -0
  70. package/package.json +30 -4
  71. package/profiles/README.md +10 -0
  72. package/profiles/anthropic-api/gsd-defaults.json +26 -0
  73. package/profiles/anthropic-api.json +18 -0
  74. package/profiles/antigravity.json +12 -0
  75. package/profiles/claude-subscription/gsd-defaults.json +26 -0
  76. package/profiles/claude-subscription.json +17 -0
  77. package/profiles/github-copilot/gsd-defaults.json +26 -0
  78. package/profiles/github-copilot.json +17 -0
  79. package/profiles/openai-api/gsd-defaults.json +26 -0
  80. package/profiles/openai-api.json +17 -0
  81. package/profiles/opencode-go/gsd-defaults.json +26 -0
  82. package/profiles/opencode-go.json +17 -0
  83. package/profiles/vertex-gemini/gsd-defaults.json +26 -0
  84. package/profiles/vertex-gemini.json +18 -0
  85. package/scripts/adhd-skill.mjs +12 -0
  86. package/scripts/behavior-diff.sh +47 -0
  87. package/scripts/bump-pins.mjs +115 -0
  88. package/scripts/check-private.sh +52 -0
  89. package/scripts/check-readme.mjs +131 -0
  90. package/scripts/ci-download.sh +20 -0
  91. package/scripts/ci-install-opencode-v2.sh +6 -0
  92. package/scripts/ci-latest-report.mjs +38 -0
  93. package/scripts/ci-timing.mjs +61 -0
  94. package/scripts/copilot-context-mode.mjs +33 -0
  95. package/scripts/labels.sh +56 -0
  96. package/scripts/lean.mjs +1319 -0
  97. package/scripts/lib/adapters/antigravity.mjs +83 -0
  98. package/scripts/lib/adapters/claude.mjs +127 -0
  99. package/scripts/lib/adapters/copilot-cli.mjs +82 -0
  100. package/scripts/lib/adapters/cursor.mjs +60 -0
  101. package/scripts/lib/adapters/opencode-v1.mjs +79 -0
  102. package/scripts/lib/adapters/opencode-v2.mjs +216 -0
  103. package/scripts/lib/adapters/vscode-copilot.mjs +56 -0
  104. package/scripts/lib/adhd.mjs +28 -0
  105. package/scripts/lib/adopt.mjs +619 -0
  106. package/scripts/lib/agent-lifecycle.mjs +280 -0
  107. package/scripts/lib/backup-stamp.mjs +25 -0
  108. package/scripts/lib/copilot-usage.mjs +49 -0
  109. package/scripts/lib/doctor.mjs +279 -0
  110. package/scripts/lib/feedback.mjs +48 -0
  111. package/scripts/lib/fsops.mjs +319 -0
  112. package/scripts/lib/gsd.mjs +42 -0
  113. package/scripts/lib/inventory.mjs +196 -0
  114. package/scripts/lib/lean-update.mjs +30 -0
  115. package/scripts/lib/logins.mjs +28 -0
  116. package/scripts/lib/migrate.mjs +407 -0
  117. package/scripts/lib/network.mjs +119 -0
  118. package/scripts/lib/node-runtime.mjs +85 -0
  119. package/scripts/lib/opencode-backup.mjs +204 -0
  120. package/scripts/lib/opencode-upgrade.mjs +441 -0
  121. package/scripts/lib/opencode1.mjs +203 -0
  122. package/scripts/lib/parallel.mjs +270 -0
  123. package/scripts/lib/pins-diff.mjs +33 -0
  124. package/scripts/lib/pins.mjs +52 -0
  125. package/scripts/lib/plugin-health.mjs +191 -0
  126. package/scripts/lib/prereqs.mjs +203 -0
  127. package/scripts/lib/project.mjs +38 -0
  128. package/scripts/lib/redact.mjs +30 -0
  129. package/scripts/lib/render.mjs +101 -0
  130. package/scripts/lib/shell-path.mjs +22 -0
  131. package/scripts/lib/summary-data.mjs +30 -0
  132. package/scripts/lib/summary-html.mjs +159 -0
  133. package/scripts/lib/system.mjs +269 -0
  134. package/scripts/lib/terminals.mjs +316 -0
  135. package/scripts/lib/ui.mjs +34 -0
  136. package/scripts/lib/unverified.mjs +49 -0
  137. package/scripts/lib/update-plan.mjs +60 -0
  138. package/scripts/lib/upgrade.mjs +231 -0
  139. package/scripts/lib/verify-commit.mjs +16 -0
  140. package/scripts/lib/verify-prompt.mjs +46 -0
  141. package/scripts/lib/verify-sha256.mjs +20 -0
  142. package/scripts/lint-workflows.mjs +25 -0
  143. package/scripts/models-refresh.mjs +58 -0
  144. package/scripts/parallel.mjs +59 -0
  145. package/scripts/pins-latest.mjs +66 -0
  146. package/scripts/release.mjs +71 -0
  147. package/scripts/verify-pins.mjs +36 -0
  148. package/scripts/version-watch.mjs +124 -0
@@ -0,0 +1,216 @@
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 { parse } from 'jsonc-parser';
8
+ import { OWNED_MARK } from '../fsops.mjs';
9
+ import { tierFor, modelFor } from '../render.mjs';
10
+ import { configHome } from '../system.mjs';
11
+ import { gitBashPath } from '../terminals.mjs';
12
+ import { PINS, npmSpec, skillSource, skillsCli } from '../pins.mjs';
13
+ import { updaterMode } from '../network.mjs';
14
+
15
+ const PERMISSIONS = {
16
+ 'read-only': [' edit: deny', ' bash: deny'],
17
+ 'git-read': [' edit: deny', ' bash:', ' "*": deny', ' "git diff*": allow', ' "git log*": allow', ' "git show*": allow', ' "git status*": allow'],
18
+ 'read-write': [],
19
+ };
20
+
21
+ export function renderOpenCodeAgent(agent, profile) {
22
+ const tier = tierFor(profile, agent.name, agent.tier);
23
+ const m = modelFor(profile, tier);
24
+ const lines = ['---', `# ${OWNED_MARK} (tier: ${tier})`, `description: ${agent.description}`, 'mode: subagent'];
25
+ if (m?.model) lines.push(`model: ${m.model}`);
26
+ for (const [k, v] of Object.entries(m?.options ?? {})) lines.push(`${k}: ${v}`);
27
+ const perms = [...PERMISSIONS[agent.access]];
28
+ if (agent.name === 'research') perms.push(' webfetch: allow');
29
+ if (perms.length) lines.push('permission:', ...perms);
30
+ lines.push('---', '', agent.body, '');
31
+ return lines.join('\n');
32
+ }
33
+
34
+ export function configPath(dir) {
35
+ for (const f of ['opencode.jsonc', 'opencode.json']) {
36
+ if (fs.existsSync(path.join(dir, f))) return path.join(dir, f);
37
+ }
38
+ return path.join(dir, 'opencode.jsonc');
39
+ }
40
+
41
+ export function localServer(core, name) {
42
+ const server = core.mcp[name];
43
+ const command = [...server.command];
44
+ if (name === 'serena') command.splice(command.indexOf('start-mcp-server') + 1, 0, '--context', server.context.default);
45
+ return { type: 'local', command, enabled: true };
46
+ }
47
+
48
+ // dcp.jsonc thresholds, shared by 1.x and 2.x. setIfAbsent keeps any value the user already set.
49
+ export function dcpConfigAction(dir, profile) {
50
+ const contextWindow = profile?.context_window ?? 200000;
51
+ return {
52
+ kind: 'json',
53
+ path: path.join(dir, 'dcp.jsonc'),
54
+ edits: [
55
+ { path: ['$schema'], value: 'https://raw.githubusercontent.com/Opencode-DCP/opencode-dynamic-context-pruning/master/dcp.schema.json', mode: 'setIfAbsent' },
56
+ { path: ['compress', 'minContextLimit'], value: Math.round(contextWindow * 0.5), mode: 'setIfAbsent' },
57
+ { path: ['compress', 'maxContextLimit'], value: Math.round(contextWindow * 0.8), mode: 'setIfAbsent' },
58
+ ],
59
+ };
60
+ }
61
+
62
+ // MCP entry edit. `shape` turns a command array into this agent's entry. A server with `legacy` commands in core/mcp.json
63
+ // (Context Mode: other versions, with or without `server`, npx or an nvm Node; `*` is a wildcard) has those entries replaced
64
+ // by a rerun, so the npx and absolute forms flip either way. Anything else the user has is kept.
65
+ export function mcpEdit(path, shape, command, legacy) {
66
+ const value = shape(command);
67
+ return legacy ? { path, value, mode: 'upgradeIf', legacy: legacy.map(shape) } : { path, value, mode: 'setIfAbsent' };
68
+ }
69
+
70
+ // Windows only, and only when Git Bash is actually found (#124 follow-up, proven in `real-opencode-shell`
71
+ // CI for both majors: setting `shell` to an absolute Git Bash path makes the bash/shell tool run there,
72
+ // PATH or not). `setIfAbsent` never overwrites a `shell` the user already set. `opts.shell === 'default'`
73
+ // opts out (`--shell default`). `opts.platform`/`opts.env` let tests fake the OS without one.
74
+ export function shellEdit(opts) {
75
+ if (opts.shell === 'default') return null;
76
+ const bash = gitBashPath({ platform: opts.platform ?? process.platform, env: opts.env ?? process.env });
77
+ return bash ? { path: ['shell'], value: bash, mode: 'setIfAbsent' } : null;
78
+ }
79
+
80
+ export function profileEdits(profile, agentsKey) {
81
+ if (!profile) return [];
82
+ const edits = [];
83
+ if (profile.main_model) edits.push({ path: ['model'], value: profile.main_model, mode: 'setIfAbsent' });
84
+ for (const [agent, tier] of Object.entries(profile.primary ?? {})) {
85
+ const m = modelFor(profile, tier);
86
+ if (!m) continue;
87
+ edits.push({ path: [agentsKey, agent, 'model'], value: m.model, mode: 'setIfAbsent' });
88
+ for (const [k, v] of Object.entries(m.options ?? {})) edits.push({ path: [agentsKey, agent, k], value: v, mode: 'setIfAbsent' });
89
+ }
90
+ return edits;
91
+ }
92
+
93
+ // Read at import, before isolate() points HOME and USERPROFILE at --home.
94
+ const REAL_HOME = os.homedir();
95
+
96
+ function ponytailConfig(home) {
97
+ if (process.platform !== 'win32') return path.join(configHome(home), 'ponytail', 'config.json');
98
+ // Only the real home may use %APPDATA%: --home must keep every write inside the temp dir.
99
+ const appData = home === REAL_HOME && process.env.APPDATA ? process.env.APPDATA : path.join(home, 'AppData', 'Roaming');
100
+ return path.join(appData, 'ponytail', 'config.json');
101
+ }
102
+
103
+ // state.json is editable, so the undo does not trust its path: it re-derives the vendor dir from HOME (the engine points it at --home)
104
+ // and refuses anything else, or a symlink, through fsops.unsafe.
105
+ const SCRIPT = (fsops, system) => `import os from 'node:os'; import path from 'node:path'; import fs from 'node:fs';
106
+ import { unsafe } from ${JSON.stringify(fsops)}; import { configHome } from ${JSON.stringify(system)};
107
+ const home = os.homedir(); const want = path.join(configHome(home), 'opencode', 'vendor', 'i-have-adhd');
108
+ const why = (process.platform === 'win32' ? (x) => x.toLowerCase() : (x) => x)(path.resolve(process.argv[1])) !== (process.platform === 'win32' ? want.toLowerCase() : want) ? 'not the path lean-agents installed' : unsafe(want, [home]);
109
+ if (why) { console.error('refusing to remove ' + process.argv[1] + ': ' + why); process.exit(1); }
110
+ fs.rmSync(want, { recursive: true, force: true });`;
111
+ const vendorUndo = (vendor) => [process.execPath, '--input-type=module', '-e',
112
+ SCRIPT(pathToFileURL(fileURLToPath(new URL('../fsops.mjs', import.meta.url))).href, pathToFileURL(fileURLToPath(new URL('../system.mjs', import.meta.url))).href), vendor];
113
+
114
+ // Everything that is the same on OpenCode 1.x and 2.x: files and commands, not config keys.
115
+ export function opencodeShared({ home, dir, core, profile, opts, v2 = false }) {
116
+ const tools = opts.tools;
117
+ const actions = [];
118
+ const commands = [];
119
+ if (tools.includes('ponytail')) {
120
+ actions.push({ kind: 'json', path: ponytailConfig(home), edits: [{ path: ['defaultMode'], value: opts.ponytailMode, mode: 'setIfAbsent' }] });
121
+ }
122
+ if (tools.includes('copilot-usage')) {
123
+ // Own folder, so the hand-made copilot-usage-tui is never touched. 1.x loads it through a tui.json entry; 2.x discovers
124
+ // plugins/<dir>/tui.js by itself (docs: opencode.ai/docs/build/plugins), so there is no config entry there.
125
+ const file = path.join(dir, 'plugins', 'lean-copilot-usage', 'tui.js');
126
+ const source = fs.readFileSync(fileURLToPath(new URL('../../../core/copilot-usage-tui.js', import.meta.url)), 'utf8');
127
+ actions.push({ kind: 'file', path: file, content: `// ${OWNED_MARK}\n${source}` });
128
+ if (!v2) actions.push({ kind: 'json', path: path.join(dir, 'tui.json'), edits: [{ path: ['plugin'], value: pathToFileURL(file).href, mode: 'arrayAdd' }] });
129
+ }
130
+ for (const agent of core.agents) {
131
+ actions.push({ kind: 'file', path: path.join(dir, 'agents', `${agent.name}.md`), content: renderOpenCodeAgent(agent, profile) });
132
+ }
133
+ // rtk (up to 1.2.1) writes a 1.x plugin that OpenCode 2 refuses to load (#179); VERIFY again when rtk supports the 2.x API.
134
+ if (tools.includes('rtk') && !v2) {
135
+ commands.push({ tool: 'rtk', desc: 'RTK plugin for OpenCode', run: [['rtk', 'init', '-g', '--opencode']], undo: [['rtk', 'init', '-g', '--opencode', '--uninstall']] });
136
+ }
137
+ if (tools.includes('i-have-adhd')) {
138
+ const vendor = path.join(dir, 'vendor', 'i-have-adhd');
139
+ commands.push({
140
+ tool: 'i-have-adhd',
141
+ desc: 'i-have-adhd checkout for OpenCode',
142
+ // The tag must still point at the pinned commit; a moved tag removes the checkout and fails the command.
143
+ run: [['git', 'clone', '--depth', '1', '--branch', PINS['i-have-adhd'].version, 'https://github.com/ayghri/i-have-adhd', vendor],
144
+ [process.execPath, fileURLToPath(new URL('../verify-commit.mjs', import.meta.url)), vendor, PINS['i-have-adhd'].sha]],
145
+ undo: [vendorUndo(vendor)],
146
+ skipIfExists: vendor,
147
+ });
148
+ actions.push({
149
+ kind: 'file',
150
+ path: path.join(dir, 'plugins', 'i-have-adhd.ts'),
151
+ content: `// ${OWNED_MARK}\nexport { default } from '../vendor/i-have-adhd/.opencode/plugins/i-have-adhd.mjs';\n`,
152
+ });
153
+ if (opts.adhdAlways) actions.push({ kind: 'file', path: path.join(dir, '.i-have-adhd-always'), content: '', force: true });
154
+ }
155
+ if (tools.includes('caveman')) {
156
+ commands.push({
157
+ tool: 'caveman',
158
+ desc: 'Caveman skills for OpenCode',
159
+ run: [['npx', '-y', skillsCli(), 'add', skillSource('caveman'), '--skill', 'caveman', 'caveman-compress', 'caveman-stats', '-a', 'opencode', '-g', '-y']],
160
+ // Without -a: `remove -a` keeps ~/.agents/skills while another detected agent may share that folder.
161
+ undo: [['npx', '-y', skillsCli(), 'remove', 'caveman', 'caveman-compress', 'caveman-stats', '-g', '-y']],
162
+ });
163
+ }
164
+ return { actions, commands };
165
+ }
166
+
167
+ export function opencodeV2Adapter({ home, core, profile, opts, rulesPath }) {
168
+ const dir = path.join(configHome(home), 'opencode');
169
+ const tools = opts.tools;
170
+ const { actions, commands } = opencodeShared({ home, dir, core, profile, opts, v2: true });
171
+ const edits = [
172
+ { path: ['$schema'], value: 'https://opencode.ai/config.json', mode: 'setIfAbsent' },
173
+ { path: ['instructions'], value: rulesPath, mode: 'arrayAdd' },
174
+ { path: ['default_agent'], value: 'plan', mode: 'setIfAbsent' },
175
+ { path: ['compaction', 'auto'], value: true, mode: 'setIfAbsent' },
176
+ { path: ['compaction', 'buffer'], value: 40000, mode: 'setIfAbsent' },
177
+ ...profileEdits(profile, 'agents'),
178
+ ];
179
+ const shell = shellEdit(opts);
180
+ if (shell) edits.push(shell);
181
+
182
+ for (const name of ['context-mode', 'serena', 'playwright', 'playwright-extension']) {
183
+ if (tools.includes(name)) edits.push(mcpEdit(['mcp', 'servers', name], (command) => ({ type: 'local', command, enabled: true }), localServer(core, name).command, core.mcp[name].legacy));
184
+ }
185
+ if (tools.includes('ponytail')) edits.push({ path: ['plugins'], value: npmSpec('ponytail'), mode: 'arrayAdd', legacy: ['@dietrichgebert/ponytail'] });
186
+ if (tools.includes('dcp')) {
187
+ const pkg = PINS['opencode-dcp'].source;
188
+ edits.push({ path: ['plugins'], value: npmSpec('opencode-dcp'), mode: 'arrayAdd', legacy: [] }); // any DCP entry already there is the user's: kept, nothing appended (#212)
189
+ actions.push(dcpConfigAction(dir, profile));
190
+ for (const file of ['tui.json', 'tui.jsonc']) {
191
+ const p = path.join(dir, file);
192
+ if (fs.existsSync(p)) {
193
+ try {
194
+ const parsed = parse(fs.readFileSync(p, 'utf8'));
195
+ const plugins = Array.isArray(parsed?.plugin) ? parsed.plugin : [];
196
+ if (plugins.some(x => typeof x === 'string' && (x === pkg || x.startsWith(`${pkg}@`)))) {
197
+ actions.push({ kind: 'json', path: p, edits: [{ path: ['plugin'], value: npmSpec('opencode-dcp'), mode: 'arrayAdd', legacy: [`${pkg}@latest`, pkg] }] });
198
+ }
199
+ } catch (e) {
200
+ // skip
201
+ }
202
+ }
203
+ }
204
+ }
205
+ if (opts.terminals?.includes('warp')) edits.push({ path: ['plugins'], value: npmSpec('warp-opencode'), mode: 'arrayAdd', legacy: ['@warp-dot-dev/opencode-warp'] });
206
+ if (opts.network.outbound === 'off') edits.push({ path: ['share'], value: 'disabled', mode: 'set' });
207
+ // Managed installs update through --update: off unless the user already set `update` (network off forces it).
208
+ if (updaterMode(opts)) edits.push({ path: ['update'], value: 'disable', mode: updaterMode(opts) });
209
+ if (opts.network.outbound === 'off') {
210
+ if (profile?.provider !== 'opencode') {
211
+ edits.push({ path: ['policies'], value: { effect: 'deny', action: 'provider.use', resource: 'opencode' }, mode: 'arrayAdd' });
212
+ }
213
+ }
214
+ actions.push({ kind: 'json', path: configPath(dir), edits });
215
+ return { actions, commands };
216
+ }
@@ -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
+ }
@@ -0,0 +1,28 @@
1
+ // i-have-adhd ships with disable-model-invocation: true, so an agent cannot load it when a
2
+ // prompt asks for it; only a typed /i-have-adhd or the always-on hook can. The owner wants
3
+ // agents to load it, so lean-agents flips the flag in the installed copies.
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const SCRIPT = fileURLToPath(new URL('../adhd-skill.mjs', import.meta.url));
9
+
10
+ export function adhdCommand(home) {
11
+ return {
12
+ tool: 'i-have-adhd',
13
+ desc: 'Let agents load the i-have-adhd skill',
14
+ run: [['node', SCRIPT, 'on', home]],
15
+ undo: [['node', SCRIPT, 'off', home]],
16
+ };
17
+ }
18
+
19
+ export const setInvocable = (text, on) => text.replace(/^disable-model-invocation: (true|false)$/m, `disable-model-invocation: ${on ? 'false' : 'true'}`);
20
+
21
+ // Every installed copy. Claude Code keeps one folder per plugin version.
22
+ export function adhdSkillFiles(home) {
23
+ const cache = path.join(home, '.claude', 'plugins', 'cache', 'i-have-adhd', 'i-have-adhd');
24
+ const versions = fs.existsSync(cache) ? fs.readdirSync(cache).map((v) => path.join(cache, v, 'skills', 'i-have-adhd', 'SKILL.md')) : [];
25
+ // skills 1.7.x writes ~/.agents/skills; 1.8 writes Antigravity's copy to ~/.gemini/config/skills.
26
+ const shared = [['.agents', 'skills'], ['.gemini', 'config', 'skills']].map((p) => path.join(home, ...p, 'i-have-adhd', 'SKILL.md'));
27
+ return [...versions, ...shared].filter((f) => fs.existsSync(f));
28
+ }