@zoraxylia/dsh-codex-adapter 0.0.0-stage → 0.1.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/.claude-plugin/marketplace.json +15 -0
- package/.claude-plugin/plugin.json +8 -0
- package/.mcp.json +8 -0
- package/LICENSE +21 -0
- package/README.de.md +480 -0
- package/README.es.md +480 -0
- package/README.fr.md +480 -0
- package/README.hi.md +480 -0
- package/README.id.md +480 -0
- package/README.ja.md +478 -0
- package/README.ko.md +480 -0
- package/README.md +483 -2
- package/README.pt.md +480 -0
- package/README.ru.md +480 -0
- package/README.th.md +480 -0
- package/README.tr.md +480 -0
- package/README.vi.md +480 -0
- package/README.zh-TW.md +478 -0
- package/README.zh.md +482 -0
- package/agents/ds-flash.md +17 -0
- package/agents/ds-pro.md +17 -0
- package/agy/agents/ds-flash.md +18 -0
- package/agy/agents/ds-pro.md +18 -0
- package/agy/skills/dsh-config/SKILL.md +6 -0
- package/agy/skills/dsh-playbook/SKILL.md +65 -0
- package/agy/skills/dsh-status/SKILL.md +6 -0
- package/codex/agents/ds-flash.toml +23 -0
- package/codex/agents/ds-pro.toml +23 -0
- package/codex/prompts/dsh-config.md +3 -0
- package/codex/prompts/dsh-playbook.md +60 -0
- package/codex/prompts/dsh-status.md +1 -0
- package/commands/config.md +9 -0
- package/commands/off.md +5 -0
- package/commands/on.md +5 -0
- package/commands/playbook.md +64 -0
- package/commands/status.md +5 -0
- package/cordis.patch.yml +4 -0
- package/docs/images/dsh-crew-host.png +0 -0
- package/docs/images/dsh-crew-jobs.png +0 -0
- package/docs/images/dsh-crew-logo.png +0 -0
- package/docs/images/dsh-crew-overview.png +0 -0
- package/grok/agents/ds-flash.md +19 -0
- package/grok/agents/ds-pro.md +19 -0
- package/grok/commands/dsh-config.md +9 -0
- package/grok/commands/dsh-playbook.md +66 -0
- package/grok/commands/dsh-status.md +5 -0
- package/lib/client.js +2684 -0
- package/lib/server.mjs +15417 -0
- package/package.json +137 -4
- package/scripts/build-client.mjs +23 -0
- package/scripts/build-mcp.mjs +43 -0
- package/scripts/fake-agy.sh +23 -0
- package/scripts/release-local.mjs +87 -0
- package/scripts/smoke-bundle.mjs +166 -0
- package/scripts/smoke-cwd.mjs +41 -0
- package/scripts/smoke-pack.mjs +285 -0
- package/scripts/smoke.mjs +79 -0
- package/scripts/verify-cli-workers.mjs +133 -0
- package/scripts/verify-wpc10-client.mjs +237 -0
- package/scripts/verify-wpc14-proc-endpoints.mjs +356 -0
- package/scripts/verify-wpc9-guardrails.mjs +432 -0
- package/src/cli-workers.mjs +396 -0
- package/src/client/index.tsx +1133 -0
- package/src/client/jobs-view.ts +374 -0
- package/src/cwd-lock.mjs +91 -0
- package/src/hub/index.mjs +643 -0
- package/src/hub-client.mjs +72 -0
- package/src/i18n.mjs +19 -0
- package/src/install/cli.mjs +34 -0
- package/src/install/install.mjs +577 -0
- package/src/jobs.mjs +289 -0
- package/src/multimodal.mjs +744 -0
- package/src/origin-guard.mjs +133 -0
- package/src/paths.mjs +43 -0
- package/src/plugin-env.mjs +65 -0
- package/src/proc-kill.mjs +208 -0
- package/src/process-info.mjs +60 -0
- package/src/provider-probe.mjs +35 -0
- package/src/server.mjs +438 -0
- package/src/status-shard.mjs +95 -0
- package/src/tier-binding.mjs +63 -0
- package/src/vision-route.mjs +139 -0
- package/src/worker-profiles.mjs +95 -0
- package/src/worker-question.mjs +22 -0
- package/statusline/statusline.sh +14 -0
- package/statusline/worker-segment.sh +35 -0
- package/worker.cordis.yml +77 -0
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
// One-click installers: register the Claude Code plugin persistently and
|
|
2
|
+
// render Codex / agy / grok agent roles with real paths. Called from the CLI
|
|
3
|
+
// entry or the DSH settings page. All edits are backed up and idempotent.
|
|
4
|
+
|
|
5
|
+
import { readFileSync, writeFileSync, mkdirSync, copyFileSync, existsSync, readdirSync, rmSync, rmdirSync } from 'node:fs';
|
|
6
|
+
import { dirname, join, resolve, relative } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
|
|
10
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
11
|
+
const MARKETPLACE_NAME = 'dsh-crew';
|
|
12
|
+
const PLUGIN_KEY = `dsh-crew@${MARKETPLACE_NAME}`;
|
|
13
|
+
const MCP_TOOLS = ['dsh_run_worker', 'dsh_spawn_worker', 'dsh_worker_status', 'dsh_worker_result', 'dsh_worker_cancel'];
|
|
14
|
+
|
|
15
|
+
function backup(file) {
|
|
16
|
+
if (existsSync(file)) {
|
|
17
|
+
const bak = `${file}.dsh-crew-backup-${Date.now()}`;
|
|
18
|
+
copyFileSync(file, bak);
|
|
19
|
+
return bak;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function readJson(file, fallback) {
|
|
25
|
+
try { return JSON.parse(readFileSync(file, 'utf8')); } catch { return fallback; }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function readText(file) {
|
|
29
|
+
try { return readFileSync(file, 'utf8'); } catch { return ''; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Remove the [header] section (plus any trailing blank lines) from TOML text.
|
|
34
|
+
* Leaves every other section byte-for-byte intact. Returns input unchanged
|
|
35
|
+
* when the section is absent.
|
|
36
|
+
*/
|
|
37
|
+
function removeTomlSection(toml, header) {
|
|
38
|
+
const lines = toml.split('\n');
|
|
39
|
+
const start = lines.findIndex((l) => l.trim() === '[' + header + ']');
|
|
40
|
+
if (start === -1) return toml;
|
|
41
|
+
let end = start + 1;
|
|
42
|
+
while (end < lines.length && !/^\s*\[/.test(lines[end])) end++;
|
|
43
|
+
while (end < lines.length && lines[end].trim() === '') end++;
|
|
44
|
+
lines.splice(start, end - start);
|
|
45
|
+
return lines.join('\n');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Quote a string as a TOML basic string. A raw Windows path between double
|
|
50
|
+
* quotes is not valid TOML: `\U` and `\n` in `C:\Users\...\node_modules`
|
|
51
|
+
* are escape sequences, so the config fails to parse (#12). JSON's escapes
|
|
52
|
+
* are a subset of TOML's, and unlike a '...' literal this survives a quote
|
|
53
|
+
* in the path (a user named O'Brien).
|
|
54
|
+
*/
|
|
55
|
+
export function tomlString(s) {
|
|
56
|
+
// DEL is the one control character JSON leaves raw and TOML rejects.
|
|
57
|
+
return JSON.stringify(String(s)).replace(/\x7f/g, '\\u007f');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// One-time migration from the pre-rename config dir (dsh-workers → dsh-crew).
|
|
61
|
+
try {
|
|
62
|
+
const oldDir = join(homedir(), '.config', 'dsh-workers');
|
|
63
|
+
const newDir = join(homedir(), '.config', 'dsh-crew');
|
|
64
|
+
if (existsSync(oldDir) && !existsSync(newDir)) {
|
|
65
|
+
const { renameSync } = await import('node:fs');
|
|
66
|
+
renameSync(oldDir, newDir);
|
|
67
|
+
}
|
|
68
|
+
} catch {}
|
|
69
|
+
|
|
70
|
+
const GLOBAL_CONFIG_FILE = join(CONFIG_DIR_HOME(), 'config.json');
|
|
71
|
+
function CONFIG_DIR_HOME() { return join(homedir(), '.config', 'dsh-crew'); }
|
|
72
|
+
|
|
73
|
+
export const GLOBAL_CONFIG_DEFAULTS = {
|
|
74
|
+
default_tier: 'flash',
|
|
75
|
+
default_effort: 'max',
|
|
76
|
+
mode: 'auto',
|
|
77
|
+
default_timeout_seconds: 1800,
|
|
78
|
+
hub_url: 'http://127.0.0.1:3080',
|
|
79
|
+
// auto = orchestrator picks the tier; flash-only / pro-only clamp every
|
|
80
|
+
// dispatch to one tier at the tool layer regardless of what was requested.
|
|
81
|
+
tier_policy: 'auto',
|
|
82
|
+
// When a blocking flash run fails, retry the same task once on pro.
|
|
83
|
+
escalate_on_failure: false,
|
|
84
|
+
// Multimodal bridge: which subscription CLI lends the text-only DS model
|
|
85
|
+
// eyes (describe_image) and a brush (generate_image).
|
|
86
|
+
vision_provider: 'claude-code', // claude-code | codex | grok | agy | <custom id> | off
|
|
87
|
+
vision_model: 'haiku', // model passed to the vision CLI; free-form
|
|
88
|
+
imagegen_provider: 'codex', // codex | agy | grok | <custom id> | off
|
|
89
|
+
// User-defined providers, each either an OpenAI-compatible HTTP endpoint or a
|
|
90
|
+
// local command. Entry shape:
|
|
91
|
+
// { id, name, type: 'api' | 'cli', models: [],
|
|
92
|
+
// api: base_url, api_key, imagegen_model
|
|
93
|
+
// cli: vision_command, imagegen_command }
|
|
94
|
+
// CLI commands run via bash with shell-quoted placeholders: vision
|
|
95
|
+
// {image} {question} {model} (stdout is the answer), imagegen
|
|
96
|
+
// {prompt} {output} {size} (must write the file to {output}).
|
|
97
|
+
custom_providers: [],
|
|
98
|
+
// User-added model ids per provider, merged into the panel's model list.
|
|
99
|
+
extra_models: {},
|
|
100
|
+
// Which LLM route each worker tier dispatches to. A provider id names a
|
|
101
|
+
// route the HOST already has configured (ctx.llm.listProviders()) — this
|
|
102
|
+
// plugin deliberately does NOT define providers of its own, so a local
|
|
103
|
+
// model (Ollama and friends) is configured once, in DSH, and merely named
|
|
104
|
+
// here. Empty string = the built-in DeepSeek default for that tier.
|
|
105
|
+
flash_provider: '',
|
|
106
|
+
flash_model: '',
|
|
107
|
+
pro_provider: '',
|
|
108
|
+
pro_model: '',
|
|
109
|
+
// Hub-mode agent preset per tier: 'default' follows the DSH roster default.
|
|
110
|
+
preset_flash: 'minimal',
|
|
111
|
+
preset_pro: 'default',
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export function readGlobalConfig() {
|
|
115
|
+
return { ...GLOBAL_CONFIG_DEFAULTS, ...readJson(GLOBAL_CONFIG_FILE, {}) };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function writeGlobalConfig(patch) {
|
|
119
|
+
mkdirSync(CONFIG_DIR_HOME(), { recursive: true });
|
|
120
|
+
const next = { ...readGlobalConfig() };
|
|
121
|
+
for (const [k, v] of Object.entries(patch ?? {})) {
|
|
122
|
+
if (v !== undefined && k in GLOBAL_CONFIG_DEFAULTS) next[k] = v;
|
|
123
|
+
}
|
|
124
|
+
writeFileSync(GLOBAL_CONFIG_FILE, JSON.stringify(next, null, 2) + '\n');
|
|
125
|
+
return next;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** What is currently installed where — drives the settings-page buttons. */
|
|
129
|
+
export function installStatus({ home = homedir() } = {}) {
|
|
130
|
+
const settings = readJson(join(home, '.claude', 'settings.json'), {});
|
|
131
|
+
const enabled = settings.enabledPlugins;
|
|
132
|
+
const claudeInstalled = !!(enabled && !Array.isArray(enabled) && enabled[PLUGIN_KEY]);
|
|
133
|
+
const hudWired = typeof settings.statusLine?.command === 'string'
|
|
134
|
+
&& settings.statusLine.command.includes('worker-segment.sh');
|
|
135
|
+
const codexInstalled = existsSync(join(home, '.codex', 'agents', 'ds-flash.toml'));
|
|
136
|
+
const agyMcp = readJson(join(home, '.gemini', 'config', 'mcp_config.json'), {});
|
|
137
|
+
const agyInstalled = !!(agyMcp.mcpServers && agyMcp.mcpServers['dsh-crew'])
|
|
138
|
+
|| existsSync(join(home, '.gemini', 'config', 'agents', 'ds-flash.md'));
|
|
139
|
+
const grokTxt = readText(join(home, '.grok', 'config.toml'));
|
|
140
|
+
const grokInstalled = grokTxt.includes('[mcp_servers.dsh-crew]')
|
|
141
|
+
|| existsSync(join(home, '.grok', 'agents', 'ds-flash.md'));
|
|
142
|
+
return {
|
|
143
|
+
claude: { installed: claudeInstalled, hud: hudWired },
|
|
144
|
+
codex: { installed: codexInstalled },
|
|
145
|
+
agy: { installed: agyInstalled },
|
|
146
|
+
grok: { installed: grokInstalled },
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function uninstallCodex({ home = homedir() } = {}) {
|
|
151
|
+
const actions = [];
|
|
152
|
+
for (const f of ['ds-flash.toml', 'ds-pro.toml']) {
|
|
153
|
+
const p = join(home, '.codex', 'agents', f);
|
|
154
|
+
if (existsSync(p)) { backup(p); rmSync(p); actions.push(`removed: ${p} (backup kept)`); }
|
|
155
|
+
}
|
|
156
|
+
for (const f of ['dsh-config.md', 'dsh-status.md', 'dsh-playbook.md']) {
|
|
157
|
+
const p = join(home, '.codex', 'prompts', f);
|
|
158
|
+
if (existsSync(p)) { rmSync(p); actions.push(`removed: ${p}`); }
|
|
159
|
+
}
|
|
160
|
+
return { ok: true, actions: actions.length ? actions : ['nothing to remove'] };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export async function installClaudeCode({ home = homedir(), statusline = false } = {}) {
|
|
164
|
+
const actions = [];
|
|
165
|
+
|
|
166
|
+
// The repo is its own marketplace: .claude-plugin/marketplace.json lists the
|
|
167
|
+
// plugin with source './'. Pointing at the parent directory instead would
|
|
168
|
+
// need a manifest written into whatever directory the user cloned into.
|
|
169
|
+
const mpDir = ROOT;
|
|
170
|
+
actions.push(`marketplace: ${mpDir} (self-marketplace, source ./)`);
|
|
171
|
+
|
|
172
|
+
// 2. settings.json: marketplace + enabledPlugins + permissions allowlist.
|
|
173
|
+
const settingsFile = join(home, '.claude', 'settings.json');
|
|
174
|
+
mkdirSync(dirname(settingsFile), { recursive: true });
|
|
175
|
+
const bak = backup(settingsFile);
|
|
176
|
+
if (bak) actions.push(`backup: ${bak}`);
|
|
177
|
+
const settings = readJson(settingsFile, {});
|
|
178
|
+
|
|
179
|
+
// Both fields are records (see json.schemastore.org/claude-code-settings.json).
|
|
180
|
+
// Older versions of this installer wrote arrays, which Claude Code ignores
|
|
181
|
+
// with a warning — migrate those in place.
|
|
182
|
+
const markets = (settings.extraKnownMarketplaces && !Array.isArray(settings.extraKnownMarketplaces)
|
|
183
|
+
&& typeof settings.extraKnownMarketplaces === 'object') ? settings.extraKnownMarketplaces : {};
|
|
184
|
+
if (Array.isArray(settings.extraKnownMarketplaces)) actions.push('migrated legacy extraKnownMarketplaces array');
|
|
185
|
+
markets[MARKETPLACE_NAME] = { source: { source: 'directory', path: mpDir } };
|
|
186
|
+
if (markets['dsh-workers']) {
|
|
187
|
+
delete markets['dsh-workers'];
|
|
188
|
+
actions.push('removed pre-rename dsh-workers marketplace entry');
|
|
189
|
+
}
|
|
190
|
+
settings.extraKnownMarketplaces = markets;
|
|
191
|
+
|
|
192
|
+
const enabled = (settings.enabledPlugins && !Array.isArray(settings.enabledPlugins)
|
|
193
|
+
&& typeof settings.enabledPlugins === 'object') ? settings.enabledPlugins : {};
|
|
194
|
+
if (Array.isArray(settings.enabledPlugins)) {
|
|
195
|
+
for (const key of settings.enabledPlugins) if (typeof key === 'string') enabled[key] = true;
|
|
196
|
+
actions.push('migrated legacy enabledPlugins array');
|
|
197
|
+
}
|
|
198
|
+
enabled[PLUGIN_KEY] = true;
|
|
199
|
+
if (enabled['dsh-workers@dsh-workers']) {
|
|
200
|
+
delete enabled['dsh-workers@dsh-workers'];
|
|
201
|
+
actions.push('removed pre-rename dsh-workers plugin entry');
|
|
202
|
+
}
|
|
203
|
+
settings.enabledPlugins = enabled;
|
|
204
|
+
|
|
205
|
+
settings.permissions = settings.permissions ?? {};
|
|
206
|
+
let allow = Array.isArray(settings.permissions.allow) ? settings.permissions.allow : [];
|
|
207
|
+
const preRename = allow.filter((r) => typeof r === 'string' && r.startsWith('mcp__plugin_dsh-workers_'));
|
|
208
|
+
if (preRename.length) {
|
|
209
|
+
allow = allow.filter((r) => !preRename.includes(r));
|
|
210
|
+
actions.push(`removed ${preRename.length} pre-rename permission rules`);
|
|
211
|
+
}
|
|
212
|
+
for (const tool of MCP_TOOLS) {
|
|
213
|
+
const rule = `mcp__plugin_dsh-crew_dsh-crew__${tool}`;
|
|
214
|
+
if (!allow.includes(rule)) allow.push(rule);
|
|
215
|
+
}
|
|
216
|
+
settings.permissions.allow = allow;
|
|
217
|
+
|
|
218
|
+
if (statusline && !settings.statusLine) {
|
|
219
|
+
settings.statusLine = { type: 'command', command: `bash ${join(ROOT, 'statusline', 'statusline.sh')}` };
|
|
220
|
+
actions.push('statusline: installed');
|
|
221
|
+
} else if (statusline) {
|
|
222
|
+
actions.push('statusline: skipped (one already configured)');
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
writeFileSync(settingsFile, JSON.stringify(settings, null, 2) + '\n');
|
|
226
|
+
actions.push(`settings: registered ${PLUGIN_KEY} + ${MCP_TOOLS.length} permission rules`);
|
|
227
|
+
|
|
228
|
+
// Materialize the install through the claude CLI: registers the marketplace
|
|
229
|
+
// in the plugin cache (settings alone leave a stale/absent cache entry) and
|
|
230
|
+
// pulls the plugin so the next session loads it. Best-effort: settings are
|
|
231
|
+
// already correct, so a missing CLI just means one manual `plugin install`.
|
|
232
|
+
if (home !== homedir()) {
|
|
233
|
+
actions.push('cli: skipped (non-default home; test mode)');
|
|
234
|
+
return { ok: true, actions };
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
const { execSync } = await import('node:child_process');
|
|
238
|
+
const run = (cmd) => execSync(cmd, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 120_000 });
|
|
239
|
+
try { run(`claude plugin marketplace add ${JSON.stringify(mpDir)}`); actions.push('cli: marketplace registered'); }
|
|
240
|
+
catch (err) {
|
|
241
|
+
// Re-adding an existing marketplace is the expected no-op; anything else
|
|
242
|
+
// is a real failure (a missing or invalid manifest, say) and must be said
|
|
243
|
+
// out loud — reporting it as "already registered" hides the cause of the
|
|
244
|
+
// `plugin install` error that follows.
|
|
245
|
+
const msg = String(err?.stdout ?? '') + String(err?.stderr ?? '') + String(err?.message ?? err);
|
|
246
|
+
if (/already/i.test(msg)) actions.push('cli: marketplace add skipped (already registered)');
|
|
247
|
+
else actions.push(`cli: marketplace add failed — ${msg.replace(/\s+/g, ' ').trim().slice(0, 160)}`);
|
|
248
|
+
}
|
|
249
|
+
// `plugin install` on an already-installed plugin is a no-op and leaves a
|
|
250
|
+
// stale snapshot in ~/.claude/plugins/cache — uninstall first so an update
|
|
251
|
+
// always re-copies the current code.
|
|
252
|
+
try { run(`claude plugin uninstall ${PLUGIN_KEY}`); } catch {}
|
|
253
|
+
run(`claude plugin install ${PLUGIN_KEY} --scope user -y`);
|
|
254
|
+
actions.push(`cli: plugin snapshot refreshed (${PLUGIN_KEY})`);
|
|
255
|
+
} catch (err) {
|
|
256
|
+
actions.push(`cli: plugin install failed — run manually: claude plugin install ${PLUGIN_KEY} -y (${String(err?.message ?? err).slice(0, 120)})`);
|
|
257
|
+
}
|
|
258
|
+
return { ok: true, actions };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function installCodex({ home = homedir(), scope } = {}) {
|
|
262
|
+
const actions = [];
|
|
263
|
+
const agentsDir = scope === 'project' ? join(process.cwd(), '.codex', 'agents') : join(home, '.codex', 'agents');
|
|
264
|
+
mkdirSync(agentsDir, { recursive: true });
|
|
265
|
+
const srcDir = join(ROOT, 'codex', 'agents');
|
|
266
|
+
for (const f of readdirSync(srcDir).filter((f) => f.endsWith('.toml'))) {
|
|
267
|
+
const dest = join(agentsDir, f);
|
|
268
|
+
const bak = backup(dest);
|
|
269
|
+
if (bak) actions.push(`backup: ${bak}`);
|
|
270
|
+
const rendered = readFileSync(join(srcDir, f), 'utf8')
|
|
271
|
+
.replace(/args = \[.*server\.mjs"\]/, () => `args = [${tomlString(join(ROOT, 'src', 'server.mjs'))}]`);
|
|
272
|
+
writeFileSync(dest, rendered);
|
|
273
|
+
actions.push(`role: ${dest}`);
|
|
274
|
+
}
|
|
275
|
+
const promptsDir = scope === 'project' ? join(process.cwd(), '.codex', 'prompts') : join(home, '.codex', 'prompts');
|
|
276
|
+
mkdirSync(promptsDir, { recursive: true });
|
|
277
|
+
const promptsSrc = join(ROOT, 'codex', 'prompts');
|
|
278
|
+
for (const f of readdirSync(promptsSrc).filter((f) => f.endsWith('.md'))) {
|
|
279
|
+
writeFileSync(join(promptsDir, f), readFileSync(join(promptsSrc, f), 'utf8'));
|
|
280
|
+
actions.push(`prompt: ${join(promptsDir, f)}`);
|
|
281
|
+
}
|
|
282
|
+
return { ok: true, actions };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// ---------- agy (Antigravity CLI) ----------
|
|
286
|
+
// Global MCP config: ~/.gemini/config/mcp_config.json
|
|
287
|
+
// { "mcpServers": { "<name>": { "command", "args", "disabled", "env"? } } }
|
|
288
|
+
// Global agents: ~/.gemini/config/agents/<name>.md (frontmatter: name,
|
|
289
|
+
// description required; model flash|pro, subagent, tools, ... optional).
|
|
290
|
+
// Global skills: ~/.gemini/config/skills/<name>/SKILL.md.
|
|
291
|
+
// After a server runs once, agy keeps tool-schema caches under
|
|
292
|
+
// ~/.gemini/{antigravity,antigravity-cli,antigravity-ide}/mcp/<name>/ —
|
|
293
|
+
// uninstall removes those too.
|
|
294
|
+
|
|
295
|
+
export function installAgy({ home = homedir() } = {}) {
|
|
296
|
+
const actions = [];
|
|
297
|
+
const serverPath = join(ROOT, 'lib', 'server.mjs');
|
|
298
|
+
if (!existsSync(serverPath)) {
|
|
299
|
+
actions.push(`warning: ${serverPath} missing — run pnpm build:mcp so the registered server can start`);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// 1. MCP server entry (idempotent; existing entry is replaced).
|
|
303
|
+
const mcpFile = join(home, '.gemini', 'config', 'mcp_config.json');
|
|
304
|
+
mkdirSync(dirname(mcpFile), { recursive: true });
|
|
305
|
+
const bak = backup(mcpFile);
|
|
306
|
+
if (bak) actions.push(`backup: ${bak}`);
|
|
307
|
+
const cfg = readJson(mcpFile, {});
|
|
308
|
+
cfg.mcpServers = cfg.mcpServers ?? {};
|
|
309
|
+
cfg.mcpServers['dsh-crew'] = { command: 'node', args: [serverPath], disabled: false };
|
|
310
|
+
writeFileSync(mcpFile, JSON.stringify(cfg, null, 2) + '\n');
|
|
311
|
+
actions.push(`mcp: registered dsh-crew (node ${serverPath}) in ${mcpFile}`);
|
|
312
|
+
|
|
313
|
+
// 2. Agent definitions (no path rendering needed — agy reads the global MCP
|
|
314
|
+
// config itself, so the roles never embed a server path).
|
|
315
|
+
const agentsDir = join(home, '.gemini', 'config', 'agents');
|
|
316
|
+
mkdirSync(agentsDir, { recursive: true });
|
|
317
|
+
for (const f of ['ds-flash.md', 'ds-pro.md']) {
|
|
318
|
+
const dest = join(agentsDir, f);
|
|
319
|
+
const b = backup(dest);
|
|
320
|
+
if (b) actions.push(`backup: ${b}`);
|
|
321
|
+
writeFileSync(dest, readFileSync(join(ROOT, 'agy', 'agents', f), 'utf8'));
|
|
322
|
+
actions.push(`agent: ${dest}`);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// 3. Skills (agy's command/prompt packaging — /skills in the CLI).
|
|
326
|
+
for (const s of ['dsh-config', 'dsh-status', 'dsh-playbook']) {
|
|
327
|
+
const dest = join(home, '.gemini', 'config', 'skills', s, 'SKILL.md');
|
|
328
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
329
|
+
const b = backup(dest);
|
|
330
|
+
if (b) actions.push(`backup: ${b}`);
|
|
331
|
+
writeFileSync(dest, readFileSync(join(ROOT, 'agy', 'skills', s, 'SKILL.md'), 'utf8'));
|
|
332
|
+
actions.push(`skill: ${dest}`);
|
|
333
|
+
}
|
|
334
|
+
return { ok: true, actions };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export function uninstallAgy({ home = homedir() } = {}) {
|
|
338
|
+
const actions = [];
|
|
339
|
+
|
|
340
|
+
const mcpFile = join(home, '.gemini', 'config', 'mcp_config.json');
|
|
341
|
+
const cfg = readJson(mcpFile, null);
|
|
342
|
+
if (cfg && cfg.mcpServers && cfg.mcpServers['dsh-crew']) {
|
|
343
|
+
backup(mcpFile);
|
|
344
|
+
delete cfg.mcpServers['dsh-crew'];
|
|
345
|
+
writeFileSync(mcpFile, JSON.stringify(cfg, null, 2) + '\n');
|
|
346
|
+
actions.push(`mcp: removed dsh-crew from ${mcpFile} (backup kept)`);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
for (const f of ['ds-flash.md', 'ds-pro.md']) {
|
|
350
|
+
const p = join(home, '.gemini', 'config', 'agents', f);
|
|
351
|
+
if (existsSync(p)) {
|
|
352
|
+
backup(p);
|
|
353
|
+
rmSync(p);
|
|
354
|
+
actions.push(`removed: ${p} (backup kept)`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
for (const s of ['dsh-config', 'dsh-status', 'dsh-playbook']) {
|
|
359
|
+
const dir = join(home, '.gemini', 'config', 'skills', s);
|
|
360
|
+
const sk = join(dir, 'SKILL.md');
|
|
361
|
+
if (existsSync(sk)) {
|
|
362
|
+
rmSync(sk);
|
|
363
|
+
try { rmdirSync(dir); } catch {}
|
|
364
|
+
actions.push(`removed skill: ${dir}`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Tool-schema caches (regenerable — agy re-creates them on next server use).
|
|
369
|
+
for (const flavour of ['antigravity', 'antigravity-cli', 'antigravity-ide']) {
|
|
370
|
+
const p = join(home, '.gemini', flavour, 'mcp', 'dsh-crew');
|
|
371
|
+
if (existsSync(p)) {
|
|
372
|
+
rmSync(p, { recursive: true, force: true });
|
|
373
|
+
actions.push(`removed mcp cache: ${p}`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
return { ok: true, actions: actions.length ? actions : ['nothing to remove'] };
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// ---------- grok (Grok Build CLI) ----------
|
|
381
|
+
// User MCP config: ~/.grok/config.toml
|
|
382
|
+
// [mcp_servers.<name>]
|
|
383
|
+
// command = "..." args = [...] enabled = true
|
|
384
|
+
// User agents: ~/.grok/agents/<name>.md (frontmatter: name, description,
|
|
385
|
+
// prompt_mode, model, permission_mode, tools, mcpInheritance, ...).
|
|
386
|
+
// User slash commands: ~/.grok/commands/<name>.md (flat files, CC legacy
|
|
387
|
+
// layout — filename stem becomes the command, $ARGUMENTS is substituted).
|
|
388
|
+
|
|
389
|
+
export function installGrok({ home = homedir() } = {}) {
|
|
390
|
+
const actions = [];
|
|
391
|
+
const serverPath = join(ROOT, 'lib', 'server.mjs');
|
|
392
|
+
if (!existsSync(serverPath)) {
|
|
393
|
+
actions.push(`warning: ${serverPath} missing — run pnpm build:mcp so the registered server can start`);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// 1. MCP server section in ~/.grok/config.toml (idempotent: replace the
|
|
397
|
+
// existing [mcp_servers.dsh-crew] block if present, keep the rest).
|
|
398
|
+
const cfgFile = join(home, '.grok', 'config.toml');
|
|
399
|
+
mkdirSync(dirname(cfgFile), { recursive: true });
|
|
400
|
+
const bak = backup(cfgFile);
|
|
401
|
+
if (bak) actions.push(`backup: ${bak}`);
|
|
402
|
+
let toml = readText(cfgFile);
|
|
403
|
+
toml = removeTomlSection(toml, 'mcp_servers.dsh-crew').replace(/\n+$/, '');
|
|
404
|
+
toml += `\n\n[mcp_servers.dsh-crew]\ncommand = "node"\nargs = [${tomlString(serverPath)}]\nenabled = true\n`;
|
|
405
|
+
writeFileSync(cfgFile, toml);
|
|
406
|
+
actions.push(`mcp: registered dsh-crew (node ${serverPath}) in ${cfgFile}`);
|
|
407
|
+
|
|
408
|
+
// 2. Agent definitions.
|
|
409
|
+
const agentsDir = join(home, '.grok', 'agents');
|
|
410
|
+
mkdirSync(agentsDir, { recursive: true });
|
|
411
|
+
for (const f of ['ds-flash.md', 'ds-pro.md']) {
|
|
412
|
+
const dest = join(agentsDir, f);
|
|
413
|
+
const b = backup(dest);
|
|
414
|
+
if (b) actions.push(`backup: ${b}`);
|
|
415
|
+
writeFileSync(dest, readFileSync(join(ROOT, 'grok', 'agents', f), 'utf8'));
|
|
416
|
+
actions.push(`agent: ${dest}`);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// 3. Slash commands (/dsh-config, /dsh-status, /dsh-playbook).
|
|
420
|
+
const commandsDir = join(home, '.grok', 'commands');
|
|
421
|
+
mkdirSync(commandsDir, { recursive: true });
|
|
422
|
+
for (const f of ['dsh-config.md', 'dsh-status.md', 'dsh-playbook.md']) {
|
|
423
|
+
const dest = join(commandsDir, f);
|
|
424
|
+
const b = backup(dest);
|
|
425
|
+
if (b) actions.push(`backup: ${b}`);
|
|
426
|
+
writeFileSync(dest, readFileSync(join(ROOT, 'grok', 'commands', f), 'utf8'));
|
|
427
|
+
actions.push(`command: ${dest}`);
|
|
428
|
+
}
|
|
429
|
+
return { ok: true, actions };
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export function uninstallGrok({ home = homedir() } = {}) {
|
|
433
|
+
const actions = [];
|
|
434
|
+
|
|
435
|
+
const cfgFile = join(home, '.grok', 'config.toml');
|
|
436
|
+
if (existsSync(cfgFile)) {
|
|
437
|
+
const before = readText(cfgFile);
|
|
438
|
+
let after = removeTomlSection(before, 'mcp_servers.dsh-crew');
|
|
439
|
+
// Drop dsh-crew from any disabled_mcp_servers list grok may have written.
|
|
440
|
+
after = after.split('\n').map((l) => (l.includes('disabled_mcp_servers') && l.includes('dsh-crew')
|
|
441
|
+
? l.replace(/"dsh-crew"\s*,?\s*/g, '').replace(/,\s*\]/g, ']')
|
|
442
|
+
: l)).join('\n');
|
|
443
|
+
if (after !== before) {
|
|
444
|
+
backup(cfgFile);
|
|
445
|
+
writeFileSync(cfgFile, after.replace(/\n{3,}$/, '\n'));
|
|
446
|
+
actions.push(`mcp: removed dsh-crew from ${cfgFile} (backup kept)`);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
for (const f of ['ds-flash.md', 'ds-pro.md']) {
|
|
451
|
+
const p = join(home, '.grok', 'agents', f);
|
|
452
|
+
if (existsSync(p)) {
|
|
453
|
+
backup(p);
|
|
454
|
+
rmSync(p);
|
|
455
|
+
actions.push(`removed: ${p} (backup kept)`);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
for (const f of ['dsh-config.md', 'dsh-status.md', 'dsh-playbook.md']) {
|
|
460
|
+
const p = join(home, '.grok', 'commands', f);
|
|
461
|
+
if (existsSync(p)) {
|
|
462
|
+
rmSync(p);
|
|
463
|
+
actions.push(`removed: ${p}`);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
return { ok: true, actions: actions.length ? actions : ['nothing to remove'] };
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Wire the DSH worker segment into an existing claude-hud statusline via its
|
|
472
|
+
* --extra-cmd hook (requires CLAUDE_HUD_ALLOW_EXTRA_CMD=1). Idempotent.
|
|
473
|
+
*/
|
|
474
|
+
export function installHudSegment({ home = homedir() } = {}) {
|
|
475
|
+
const settingsFile = join(home, '.claude', 'settings.json');
|
|
476
|
+
const settings = readJson(settingsFile, null);
|
|
477
|
+
if (!settings) return { ok: false, actions: ['settings.json not found'] };
|
|
478
|
+
const cmd = settings.statusLine?.command;
|
|
479
|
+
if (typeof cmd !== 'string' || !cmd.includes('claude-hud')) {
|
|
480
|
+
return { ok: false, actions: ['statusLine is not claude-hud; use statusline/statusline.sh directly instead'] };
|
|
481
|
+
}
|
|
482
|
+
const segment = join(ROOT, 'statusline', 'worker-segment.sh');
|
|
483
|
+
if (cmd.includes(segment)) return { ok: true, actions: ['already wired'] };
|
|
484
|
+
if (cmd.includes('worker-segment.sh')) {
|
|
485
|
+
// Wired to a stale copy (e.g. pre-rename path) — repoint the --extra-cmd at the current segment.
|
|
486
|
+
const next = cmd.replace(/--extra-cmd "bash [^"]*worker-segment\.sh"/, `--extra-cmd "bash ${segment}"`);
|
|
487
|
+
if (next === cmd) return { ok: false, actions: ['worker-segment.sh present but path not replaceable; rewire manually'] };
|
|
488
|
+
const bak = backup(settingsFile);
|
|
489
|
+
settings.statusLine.command = next;
|
|
490
|
+
writeFileSync(settingsFile, JSON.stringify(settings, null, 2) + '\n');
|
|
491
|
+
return { ok: true, actions: [...(bak ? [`backup: ${bak}`] : []), `statusLine: repointed worker-segment.sh to ${segment}`] };
|
|
492
|
+
}
|
|
493
|
+
let next = cmd;
|
|
494
|
+
if (!next.includes('CLAUDE_HUD_ALLOW_EXTRA_CMD')) {
|
|
495
|
+
next = next.replace(/exec\s+/, 'exec env CLAUDE_HUD_ALLOW_EXTRA_CMD=1 ');
|
|
496
|
+
if (!next.includes('CLAUDE_HUD_ALLOW_EXTRA_CMD')) return { ok: false, actions: ['could not find exec in statusLine command; wire manually'] };
|
|
497
|
+
}
|
|
498
|
+
const extra = ` --extra-cmd "bash ${segment}"`;
|
|
499
|
+
if (next.endsWith("'")) next = next.slice(0, -1) + extra + "'";
|
|
500
|
+
else next += extra;
|
|
501
|
+
const bak = backup(settingsFile);
|
|
502
|
+
settings.statusLine.command = next;
|
|
503
|
+
writeFileSync(settingsFile, JSON.stringify(settings, null, 2) + '\n');
|
|
504
|
+
return { ok: true, actions: [...(bak ? [`backup: ${bak}`] : []), 'statusLine: claude-hud now runs worker-segment.sh via --extra-cmd'] };
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Array-form extraKnownMarketplaces entries are keyed objects shaped like
|
|
509
|
+
* { "dsh-crew": { source: { source: 'directory', path } } } — never arrays
|
|
510
|
+
* of paths. Match any element that names this marketplace, or whose
|
|
511
|
+
* directory (source.path, or a top-level path for safety) resolves to the
|
|
512
|
+
* repo ROOT this installer registers.
|
|
513
|
+
*/
|
|
514
|
+
function isDshMarketplaceEntry(entry) {
|
|
515
|
+
if (!entry || typeof entry !== 'object') return false;
|
|
516
|
+
if (Object.prototype.hasOwnProperty.call(entry, MARKETPLACE_NAME)) return true;
|
|
517
|
+
const candidates = [entry, ...Object.values(entry).filter((v) => v && typeof v === 'object')];
|
|
518
|
+
return candidates.some((v) => {
|
|
519
|
+
const p = v.path ?? v.source?.path;
|
|
520
|
+
return typeof p === 'string' && resolve(p) === ROOT;
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export async function uninstallClaudeCode({ home = homedir() } = {}) {
|
|
525
|
+
const actions = [];
|
|
526
|
+
const settingsFile = join(home, '.claude', 'settings.json');
|
|
527
|
+
const settings = readJson(settingsFile, null);
|
|
528
|
+
if (!settings) return { ok: true, actions: ['settings.json not found'] };
|
|
529
|
+
backup(settingsFile);
|
|
530
|
+
if (Array.isArray(settings.extraKnownMarketplaces)) {
|
|
531
|
+
settings.extraKnownMarketplaces = settings.extraKnownMarketplaces.filter((m) => !isDshMarketplaceEntry(m));
|
|
532
|
+
} else if (settings.extraKnownMarketplaces) {
|
|
533
|
+
delete settings.extraKnownMarketplaces[MARKETPLACE_NAME];
|
|
534
|
+
}
|
|
535
|
+
if (Array.isArray(settings.enabledPlugins)) {
|
|
536
|
+
settings.enabledPlugins = settings.enabledPlugins.filter((p) => p !== PLUGIN_KEY);
|
|
537
|
+
} else if (settings.enabledPlugins) {
|
|
538
|
+
delete settings.enabledPlugins[PLUGIN_KEY];
|
|
539
|
+
}
|
|
540
|
+
if (settings.permissions?.allow) {
|
|
541
|
+
settings.permissions.allow = settings.permissions.allow.filter((r) => !r.startsWith('mcp__plugin_dsh-crew_'));
|
|
542
|
+
}
|
|
543
|
+
writeFileSync(settingsFile, JSON.stringify(settings, null, 2) + '\n');
|
|
544
|
+
actions.push('settings: unregistered from settings.json (backup kept)');
|
|
545
|
+
|
|
546
|
+
// Mirror install: the CLI keeps its own plugin state — known_marketplaces
|
|
547
|
+
// and the cache snapshot in ~/.claude/plugins/ — that rewriting settings
|
|
548
|
+
// alone never removes, so `claude plugin list` would still show the plugin
|
|
549
|
+
// as disabled. Best-effort, exactly like install: settings are already
|
|
550
|
+
// clean, so a missing CLI just leaves the two commands below manual.
|
|
551
|
+
if (home !== homedir()) {
|
|
552
|
+
actions.push('cli: skipped (non-default home; test mode)');
|
|
553
|
+
actions.push('unregistered from settings.json (backup kept)');
|
|
554
|
+
return { ok: true, actions };
|
|
555
|
+
}
|
|
556
|
+
const cliErrors = [];
|
|
557
|
+
try {
|
|
558
|
+
const { execSync } = await import('node:child_process');
|
|
559
|
+
const run = (cmd) => execSync(cmd, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 120_000 });
|
|
560
|
+
for (const cmd of ['claude plugin uninstall ' + PLUGIN_KEY, 'claude plugin marketplace remove ' + MARKETPLACE_NAME]) {
|
|
561
|
+
try { run(cmd); } catch (err) {
|
|
562
|
+
const msg = String(err?.stdout ?? '') + String(err?.stderr ?? '') + String(err?.message ?? err);
|
|
563
|
+
cliErrors.push(msg.replace(/\s+/g, ' ').trim().slice(0, 160));
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
} catch (err) {
|
|
567
|
+
cliErrors.push(String(err?.message ?? err).slice(0, 120));
|
|
568
|
+
}
|
|
569
|
+
if (cliErrors.length) {
|
|
570
|
+
actions.push('cli: cleanup failed — run manually: claude plugin uninstall ' + PLUGIN_KEY + '; claude plugin marketplace remove ' + MARKETPLACE_NAME + ' (' + cliErrors.join(' | ') + ')');
|
|
571
|
+
actions.push('settings.json was cleaned (backup kept) but the Claude Code CLI cleanup failed — run the commands above manually');
|
|
572
|
+
return { ok: true, actions };
|
|
573
|
+
}
|
|
574
|
+
actions.push('cli: uninstalled ' + PLUGIN_KEY + ' and removed marketplace ' + MARKETPLACE_NAME);
|
|
575
|
+
actions.push('uninstalled from Claude Code CLI and unregistered from settings.json (backup kept)');
|
|
576
|
+
return { ok: true, actions };
|
|
577
|
+
}
|