cadre-ai 1.1.1 → 2.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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  // AUTO-GENERATED by pnpm build from src/*.ts -- do not edit by hand.
3
3
  // Edit TypeScript sources under src/ instead.
4
- const __CADRE_SKILL_SHIM__ = "---\nname: cadre\ndescription: |\n Context-driven development methodology for organized, spec-first coding. Use when:\n - Project has a `cadre/` directory\n - User mentions specs, plans, tracks, or context-driven development\n - Files like `cadre/tracks.json`, `cadre/product.json`, or `cadre/workflow.json` exist\n - User asks about project status, implementation progress, or track management\n - User wants to organize development work with TDD practices\n - User asks for a `cadre-*` workflow (setup, newtrack, implement, status, revert, validate, flag, revise, review, ship, land, archive, release, handoff, refresh, formula, artifacts)\n - User mentions documentation is outdated or wants to sync context with codebase changes\n - Project is a polyrepo control repo (`cadre/repos.json` with mode \"polyrepo\") spanning git-submodule product repos\n\n Interoperable across Claude Code and OpenAI Codex.\n Uses native Cadre state for persistent task memory across sessions.\n---\n\n# Cadre Skill Shim\n\nCadre MCP is required for every Cadre workflow. Before acting, verify the MCP\nruntime with `cadre_project` using `{\"action\":\"ping\"}`. If Cadre MCP tools or\nresources are unavailable, halt and ask the user to install, enable, or restart\nthe Cadre plugin.\n\nLoad `cadre://skill-contract` for the authoritative `cadre.skill.v1` contract.\nUse `cadre://workflow-protocols` to discover workflow protocol resources, then\nload `cadre://workflow-protocol?workflow=<name>` for the active workflow.\nReferences and template inventory are also MCP-served through Cadre resources.\n";
4
+ const __CADRE_SKILL_SHIM__ = "---\nname: cadre\ndescription: |\n Context-driven development methodology for organized, spec-first coding. Use when:\n - Project has a `cadre/` directory\n - User mentions specs, plans, tracks, or context-driven development\n - Files like `cadre/tracks.json`, `cadre/product.json`, or `cadre/workflow.json` exist\n - User asks about project status, implementation progress, or track management\n - User wants to organize development work with TDD practices\n - User asks for a `cadre-*` workflow (setup, newtrack, implement, debug, status, revert, validate, flag, revise, review, ship, land, archive, release, handoff, refresh, formula, artifacts)\n - User mentions documentation is outdated or wants to sync context with codebase changes\n - Project is a polyrepo control repo (`cadre/repos.json` with mode \"polyrepo\") spanning git-submodule product repos\n\n Interoperable across Claude Code, OpenAI Codex, Copilot, and Antigravity.\n Uses native Cadre state for persistent task memory across sessions.\n---\n\n# Cadre Skill Shim\n\nCadre MCP is required for every Cadre workflow. Before acting, verify the MCP\nruntime with `cadre_project` using `{\"action\":\"ping\"}`. If Cadre MCP tools or\nresources are unavailable, halt and ask the user to install, enable, or restart\nthe Cadre plugin.\n\nLoad `cadre://skill-contract` for the authoritative `cadre.skill.v1` contract.\nUse `cadre://workflow-protocols` to discover workflow protocol resources, then\nload `cadre://workflow-protocol?workflow=<name>` for the active workflow.\nReferences and template inventory are also MCP-served through Cadre resources.\n\nFor staged approvals, stay on Cadre's packet-led review path: use the returned\n`approval.current_stage` and current review output first. Target mode may have\n`manifest_path:null`, `mutates_worktree:true`, and `files[].target_path` /\n`review_path`; bundle mode uses the manifest and temp review paths. Ask for\nexplicit user approval before sending approval fields. Avoid extra inspection\nunless packet evidence cannot answer the current stage question.\n";
5
5
  "use strict";
6
6
  var __create = Object.create;
7
7
  var __defProp = Object.defineProperty;
@@ -27,60 +27,28 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
 
29
29
  // src/cli/install.ts
30
+ var import_node_fs4 = __toESM(require("node:fs"));
31
+ var import_node_os3 = __toESM(require("node:os"));
32
+ var import_node_path5 = __toESM(require("node:path"));
33
+
34
+ // src/cli/client-approvals.ts
30
35
  var import_node_fs = __toESM(require("node:fs"));
36
+ var import_node_os2 = __toESM(require("node:os"));
37
+ var import_node_path2 = __toESM(require("node:path"));
38
+
39
+ // src/cli/install-targets.ts
31
40
  var import_node_os = __toESM(require("node:os"));
32
41
  var import_node_path = __toESM(require("node:path"));
33
42
  var import_node_child_process = require("node:child_process");
43
+ var INSTALL_TARGETS = ["codex", "claude", "copilot", "antigravity"];
44
+ var TARGET_COMMANDS = {
45
+ codex: "codex",
46
+ claude: "claude",
47
+ copilot: "copilot",
48
+ antigravity: "agy"
49
+ };
34
50
  var PACKAGE_PLUGIN_NAME = "cadre";
35
51
  var PACKAGE_DISPLAY_NAME = "Cadre";
36
- var MARKETPLACE_PLUGIN_SOURCE = "./plugins/cadre";
37
- function usage() {
38
- return [
39
- "Cadre CLI",
40
- "",
41
- "Usage:",
42
- " cadre install [--target codex|claude|all] [--scope user|project|local] [--dry-run] [--check] [--force] [--yes]",
43
- " cadre doctor",
44
- " cadre help"
45
- ].join("\n");
46
- }
47
- function parseInstall(argv) {
48
- const parsed = {
49
- target: "auto",
50
- scope: "user",
51
- dryRun: false,
52
- check: false,
53
- force: false,
54
- yes: false,
55
- cadreHome: process.env.CADRE_HOME || import_node_path.default.join(import_node_os.default.homedir(), ".cadre")
56
- };
57
- for (let index = 0; index < argv.length; index += 1) {
58
- const arg = argv[index];
59
- if (arg === "--dry-run") parsed.dryRun = true;
60
- else if (arg === "--check") parsed.check = true;
61
- else if (arg === "--force") parsed.force = true;
62
- else if (arg === "--yes" || arg === "-y") parsed.yes = true;
63
- else if (arg === "--target") {
64
- const value = argv[index + 1];
65
- if (value !== "codex" && value !== "claude" && value !== "all") throw new Error("--target must be codex, claude, or all");
66
- parsed.target = value;
67
- index += 1;
68
- } else if (arg === "--scope") {
69
- const value = argv[index + 1];
70
- if (value !== "user" && value !== "project" && value !== "local") throw new Error("--scope must be user, project, or local");
71
- parsed.scope = value;
72
- index += 1;
73
- } else if (arg === "--home") {
74
- const value = argv[index + 1];
75
- if (!value) throw new Error("--home requires a path");
76
- parsed.cadreHome = import_node_path.default.resolve(value);
77
- index += 1;
78
- } else {
79
- throw new Error(`Unknown install option: ${arg}`);
80
- }
81
- }
82
- return parsed;
83
- }
84
52
  function runtimePaths() {
85
53
  const runtimeRoot = import_node_path.default.resolve(__dirname, "..");
86
54
  return {
@@ -94,21 +62,430 @@ function commandExists(command) {
94
62
  return result.status === 0;
95
63
  }
96
64
  function selectedTargets(options) {
97
- if (options.target === "codex" || options.target === "claude") return [options.target];
98
- if (options.target === "all") return ["codex", "claude"];
99
- return ["codex", "claude"].filter((target) => commandExists(target));
65
+ if (options.target !== "auto" && options.target !== "all") return [options.target];
66
+ if (options.target === "all") return [...INSTALL_TARGETS];
67
+ return INSTALL_TARGETS.filter((target) => commandExists(TARGET_COMMANDS[target]));
100
68
  }
101
- function targetPaths(home, target) {
69
+ function antigravityCliHome() {
70
+ return process.env.ANTIGRAVITY_CLI_HOME || import_node_path.default.join(process.env.GEMINI_HOME || import_node_path.default.join(import_node_os.default.homedir(), ".gemini"), "antigravity-cli");
71
+ }
72
+ function antigravityIdeHome() {
73
+ return process.env.ANTIGRAVITY_IDE_HOME || import_node_path.default.join(process.env.GEMINI_HOME || import_node_path.default.join(import_node_os.default.homedir(), ".gemini"), "config");
74
+ }
75
+ function targetPaths(home, target, scope, cwd = process.cwd()) {
76
+ if (target === "copilot" && scope !== "user") {
77
+ const skillRoot = import_node_path.default.join(cwd, ".github", "skills", PACKAGE_PLUGIN_NAME);
78
+ return { primaryRoot: skillRoot, pluginRoots: [], skillRoots: [skillRoot] };
79
+ }
80
+ if (target === "antigravity") {
81
+ if (scope !== "user") {
82
+ const pluginRoot2 = import_node_path.default.join(cwd, ".agents", "plugins", PACKAGE_PLUGIN_NAME);
83
+ return { primaryRoot: pluginRoot2, pluginRoots: [pluginRoot2], skillRoots: [] };
84
+ }
85
+ const cliPlugin = import_node_path.default.join(antigravityCliHome(), "plugins", PACKAGE_PLUGIN_NAME);
86
+ const idePlugin = import_node_path.default.join(antigravityIdeHome(), "plugins", PACKAGE_PLUGIN_NAME);
87
+ return { primaryRoot: cliPlugin, pluginRoots: [cliPlugin, idePlugin], skillRoots: [] };
88
+ }
102
89
  const marketplaceRoot = import_node_path.default.join(home, "marketplaces", target);
103
- return {
104
- pluginRoot: import_node_path.default.join(marketplaceRoot, "plugins", PACKAGE_PLUGIN_NAME),
90
+ const pluginRoot = import_node_path.default.join(marketplaceRoot, "plugins", PACKAGE_PLUGIN_NAME);
91
+ const marketplaceFile = target === "codex" ? import_node_path.default.join(marketplaceRoot, ".agents", "plugins", "marketplace.json") : target === "claude" ? import_node_path.default.join(marketplaceRoot, ".claude-plugin", "marketplace.json") : void 0;
92
+ const paths = {
93
+ primaryRoot: pluginRoot,
105
94
  marketplaceRoot,
106
- marketplaceFile: target === "codex" ? import_node_path.default.join(marketplaceRoot, ".agents", "plugins", "marketplace.json") : import_node_path.default.join(marketplaceRoot, ".claude-plugin", "marketplace.json")
95
+ pluginRoots: [pluginRoot],
96
+ skillRoots: []
97
+ };
98
+ if (marketplaceFile) paths.marketplaceFile = marketplaceFile;
99
+ return paths;
100
+ }
101
+ function installCommands(target, paths, scope) {
102
+ if (target === "codex") {
103
+ return [
104
+ { command: "codex", args: ["plugin", "marketplace", "add", paths.marketplaceRoot || ""] },
105
+ { command: "codex", args: ["plugin", "add", "cadre@cadre"] }
106
+ ];
107
+ }
108
+ if (target === "claude") {
109
+ return [
110
+ { command: "claude", args: ["plugin", "marketplace", "add", "--scope", scope, paths.marketplaceRoot || ""] },
111
+ { command: "claude", args: ["plugin", "install", "--scope", scope, "cadre@cadre"] },
112
+ { command: "claude", args: ["plugin", "update", "--scope", scope, "cadre@cadre"] }
113
+ ];
114
+ }
115
+ if (target === "copilot" && scope === "user") {
116
+ return [{ command: "copilot", args: ["plugin", "install", paths.primaryRoot] }];
117
+ }
118
+ if (target === "antigravity" && scope === "user") {
119
+ return [{ command: "agy", args: ["plugin", "install", paths.primaryRoot], optional: true }];
120
+ }
121
+ return [];
122
+ }
123
+ function uninstallCommands(target, paths, scope) {
124
+ if (target === "codex") {
125
+ return [
126
+ { command: "codex", args: ["plugin", "remove", "cadre@cadre"], optional: true },
127
+ { command: "codex", args: ["plugin", "marketplace", "remove", PACKAGE_PLUGIN_NAME], optional: true }
128
+ ];
129
+ }
130
+ if (target === "claude") {
131
+ return [
132
+ { command: "claude", args: ["plugin", "uninstall", "--scope", scope, "--yes", "cadre@cadre"], optional: true },
133
+ { command: "claude", args: ["plugin", "marketplace", "remove", "--scope", scope, PACKAGE_PLUGIN_NAME], optional: true }
134
+ ];
135
+ }
136
+ if (target === "copilot" && scope === "user") {
137
+ return [{ command: "copilot", args: ["plugin", "uninstall", paths.primaryRoot], optional: true }];
138
+ }
139
+ if (target === "antigravity" && scope === "user") {
140
+ return [{ command: "agy", args: ["plugin", "uninstall", PACKAGE_PLUGIN_NAME], optional: true }];
141
+ }
142
+ return [];
143
+ }
144
+
145
+ // src/cli/client-approvals.ts
146
+ var CADRE_MCP_TOOLS = [
147
+ "cadre_resource",
148
+ "cadre_workflow",
149
+ "cadre_project",
150
+ "cadre_status",
151
+ "cadre_track",
152
+ "cadre_parallel",
153
+ "cadre_mutate",
154
+ "cadre_complete_task",
155
+ "cadre_job",
156
+ "cadre_review",
157
+ "cadre_intel",
158
+ "cadre_artifact"
159
+ ];
160
+ var CLAUDE_CADRE_ALLOW_RULES = [
161
+ "mcp__plugin_cadre_cadre__*",
162
+ "mcp__cadre__*"
163
+ ];
164
+ var ANTIGRAVITY_CADRE_ALLOW_RULES = [
165
+ "mcp(cadre/*)"
166
+ ];
167
+ function approvalConfigPath(target) {
168
+ if (target === "codex") {
169
+ return import_node_path2.default.join(process.env.CODEX_HOME || import_node_path2.default.join(import_node_os2.default.homedir(), ".codex"), "config.toml");
170
+ }
171
+ if (target === "claude") {
172
+ return import_node_path2.default.join(process.env.CLAUDE_HOME || process.env.CLAUDE_CONFIG_DIR || import_node_path2.default.join(import_node_os2.default.homedir(), ".claude"), "settings.json");
173
+ }
174
+ if (target === "antigravity") return import_node_path2.default.join(antigravityCliHome(), "settings.json");
175
+ return import_node_path2.default.join(process.env.COPILOT_HOME || import_node_path2.default.join(import_node_os2.default.homedir(), ".copilot"), "permissions-config.json");
176
+ }
177
+ function bootstrapClientApprovals(target) {
178
+ if (target === "codex") return bootstrapCodexApprovals();
179
+ if (target === "claude") return bootstrapClaudeApprovals();
180
+ if (target === "antigravity") return bootstrapAntigravityApprovals();
181
+ return copilotPromptResult();
182
+ }
183
+ function checkClientApprovals(target) {
184
+ if (target === "codex") return checkCodexApprovals();
185
+ if (target === "claude") return checkClaudeApprovals();
186
+ if (target === "antigravity") return checkAntigravityApprovals();
187
+ return copilotPromptResult();
188
+ }
189
+ function approvalSummary(target) {
190
+ const file = approvalConfigPath(target);
191
+ if (target === "codex") return `Cadre codex MCP tool approvals: ${file}`;
192
+ if (target === "claude") return `Cadre claude MCP tool approvals: ${file}`;
193
+ if (target === "antigravity") return `Cadre antigravity CLI MCP allow rule: ${file}`;
194
+ return "Cadre copilot MCP tools may prompt on first use; no approval file is edited";
195
+ }
196
+ function codexToolSection(tool) {
197
+ return `[plugins."cadre@cadre".mcp_servers.cadre.tools.${tool}]`;
198
+ }
199
+ function codexApprovalSnippet(tool) {
200
+ return `${codexToolSection(tool)}
201
+ approval_mode = "approve"
202
+ `;
203
+ }
204
+ function bootstrapCodexApprovals() {
205
+ const file = approvalConfigPath("codex");
206
+ let text = "";
207
+ if (import_node_fs.default.existsSync(file)) text = import_node_fs.default.readFileSync(file, "utf8");
208
+ const before = text;
209
+ for (const tool of CADRE_MCP_TOOLS) text = upsertCodexApproval(text, tool);
210
+ if (text !== before) {
211
+ import_node_fs.default.mkdirSync(import_node_path2.default.dirname(file), { recursive: true });
212
+ import_node_fs.default.writeFileSync(file, text);
213
+ }
214
+ return { ok: true, target: "codex", path: file, changed: text !== before, configured: true, rules: [...CADRE_MCP_TOOLS] };
215
+ }
216
+ function checkCodexApprovals() {
217
+ const file = approvalConfigPath("codex");
218
+ if (!import_node_fs.default.existsSync(file)) {
219
+ return { ok: false, target: "codex", path: file, changed: false, configured: false, rules: [...CADRE_MCP_TOOLS], error: `missing ${file}` };
220
+ }
221
+ const text = import_node_fs.default.readFileSync(file, "utf8");
222
+ const missing = CADRE_MCP_TOOLS.filter((tool) => !codexToolApproved(text, tool));
223
+ const result = {
224
+ ok: missing.length === 0,
225
+ target: "codex",
226
+ path: file,
227
+ changed: false,
228
+ configured: missing.length === 0,
229
+ rules: missing.length === 0 ? [...CADRE_MCP_TOOLS] : missing
107
230
  };
231
+ if (missing.length > 0) result.error = `missing Codex Cadre tool approvals: ${missing.join(", ")}`;
232
+ return result;
233
+ }
234
+ function upsertCodexApproval(text, tool) {
235
+ let next = text.endsWith("\n") || text.length === 0 ? text : `${text}
236
+ `;
237
+ const header = codexToolSection(tool);
238
+ const lines = next.split("\n");
239
+ const start = lines.findIndex((line) => line.trim() === header);
240
+ if (start === -1) {
241
+ const spacer = next.trim().length > 0 && !next.endsWith("\n\n") ? "\n" : "";
242
+ return `${next}${spacer}${codexApprovalSnippet(tool)}`;
243
+ }
244
+ let end = lines.length;
245
+ for (let index = start + 1; index < lines.length; index += 1) {
246
+ if (lines[index]?.trim().startsWith("[")) {
247
+ end = index;
248
+ break;
249
+ }
250
+ }
251
+ for (let index = start + 1; index < end; index += 1) {
252
+ if (/^\s*approval_mode\s*=/.test(lines[index] || "")) {
253
+ lines[index] = 'approval_mode = "approve"';
254
+ return lines.join("\n");
255
+ }
256
+ }
257
+ lines.splice(start + 1, 0, 'approval_mode = "approve"');
258
+ return lines.join("\n");
259
+ }
260
+ function codexToolApproved(text, tool) {
261
+ const lines = text.split(/\r?\n/);
262
+ const header = codexToolSection(tool);
263
+ const start = lines.findIndex((line) => line.trim() === header);
264
+ if (start === -1) return false;
265
+ for (let index = start + 1; index < lines.length; index += 1) {
266
+ const line = lines[index]?.trim() || "";
267
+ if (line.startsWith("[")) return false;
268
+ if (line === 'approval_mode = "approve"' || line === "approval_mode = 'approve'") return true;
269
+ }
270
+ return false;
271
+ }
272
+ function bootstrapClaudeApprovals() {
273
+ const file = approvalConfigPath("claude");
274
+ const parsed = readClaudeSettings(file);
275
+ if (!parsed.ok) return parsed.result;
276
+ const settings = parsed.settings;
277
+ const permissions = isRecord(settings.permissions) ? settings.permissions : {};
278
+ const currentAllow = Array.isArray(permissions.allow) ? permissions.allow.filter((item) => typeof item === "string") : [];
279
+ const nextAllow = [...currentAllow];
280
+ for (const rule of CLAUDE_CADRE_ALLOW_RULES) {
281
+ if (!nextAllow.includes(rule)) nextAllow.push(rule);
282
+ }
283
+ const changed = nextAllow.length !== currentAllow.length || !isRecord(settings.permissions) || !Array.isArray(permissions.allow);
284
+ if (changed) {
285
+ settings.permissions = { ...permissions, allow: nextAllow };
286
+ import_node_fs.default.mkdirSync(import_node_path2.default.dirname(file), { recursive: true });
287
+ import_node_fs.default.writeFileSync(file, `${JSON.stringify(settings, null, 2)}
288
+ `);
289
+ }
290
+ return { ok: true, target: "claude", path: file, changed, configured: true, rules: [...CLAUDE_CADRE_ALLOW_RULES] };
291
+ }
292
+ function checkClaudeApprovals() {
293
+ const file = approvalConfigPath("claude");
294
+ const parsed = readClaudeSettings(file);
295
+ if (!parsed.ok) return parsed.result;
296
+ const permissions = isRecord(parsed.settings.permissions) ? parsed.settings.permissions : {};
297
+ const allow = Array.isArray(permissions.allow) ? permissions.allow.filter((item) => typeof item === "string") : [];
298
+ const missing = CLAUDE_CADRE_ALLOW_RULES.filter((rule) => !allow.includes(rule));
299
+ const result = {
300
+ ok: missing.length === 0,
301
+ target: "claude",
302
+ path: file,
303
+ changed: false,
304
+ configured: missing.length === 0,
305
+ rules: missing.length === 0 ? [...CLAUDE_CADRE_ALLOW_RULES] : missing
306
+ };
307
+ if (missing.length > 0) result.error = `missing Claude Cadre tool allow rules: ${missing.join(", ")}`;
308
+ return result;
309
+ }
310
+ function bootstrapAntigravityApprovals() {
311
+ const file = approvalConfigPath("antigravity");
312
+ const parsed = readJsonSettings(file, "antigravity", ANTIGRAVITY_CADRE_ALLOW_RULES);
313
+ if (!parsed.ok) return parsed.result;
314
+ const settings = parsed.settings;
315
+ const permissions = isRecord(settings.permissions) ? settings.permissions : {};
316
+ const currentAllow = Array.isArray(permissions.allow) ? permissions.allow.filter((item) => typeof item === "string") : [];
317
+ const nextAllow = [...currentAllow];
318
+ for (const rule of ANTIGRAVITY_CADRE_ALLOW_RULES) {
319
+ if (!nextAllow.includes(rule)) nextAllow.push(rule);
320
+ }
321
+ const changed = nextAllow.length !== currentAllow.length || !isRecord(settings.permissions) || !Array.isArray(permissions.allow);
322
+ if (changed) {
323
+ settings.permissions = { ...permissions, allow: nextAllow };
324
+ import_node_fs.default.mkdirSync(import_node_path2.default.dirname(file), { recursive: true });
325
+ import_node_fs.default.writeFileSync(file, `${JSON.stringify(settings, null, 2)}
326
+ `);
327
+ }
328
+ return { ok: true, target: "antigravity", path: file, changed, configured: true, rules: [...ANTIGRAVITY_CADRE_ALLOW_RULES] };
329
+ }
330
+ function checkAntigravityApprovals() {
331
+ const file = approvalConfigPath("antigravity");
332
+ const parsed = readJsonSettings(file, "antigravity", ANTIGRAVITY_CADRE_ALLOW_RULES);
333
+ if (!parsed.ok) return parsed.result;
334
+ const permissions = isRecord(parsed.settings.permissions) ? parsed.settings.permissions : {};
335
+ const allow = Array.isArray(permissions.allow) ? permissions.allow.filter((item) => typeof item === "string") : [];
336
+ const missing = ANTIGRAVITY_CADRE_ALLOW_RULES.filter((rule) => !allow.includes(rule));
337
+ const result = {
338
+ ok: missing.length === 0,
339
+ target: "antigravity",
340
+ path: file,
341
+ changed: false,
342
+ configured: missing.length === 0,
343
+ rules: missing.length === 0 ? [...ANTIGRAVITY_CADRE_ALLOW_RULES] : missing
344
+ };
345
+ if (missing.length > 0) result.error = `missing Antigravity Cadre tool allow rules: ${missing.join(", ")}`;
346
+ return result;
347
+ }
348
+ function copilotPromptResult() {
349
+ return {
350
+ ok: true,
351
+ target: "copilot",
352
+ path: approvalConfigPath("copilot"),
353
+ changed: false,
354
+ configured: false,
355
+ rules: []
356
+ };
357
+ }
358
+ function readClaudeSettings(file) {
359
+ return readJsonSettings(file, "claude", CLAUDE_CADRE_ALLOW_RULES);
360
+ }
361
+ function readJsonSettings(file, target, rules) {
362
+ if (!import_node_fs.default.existsSync(file)) return { ok: true, settings: {} };
363
+ try {
364
+ const parsed = JSON.parse(import_node_fs.default.readFileSync(file, "utf8"));
365
+ if (isRecord(parsed)) return { ok: true, settings: parsed };
366
+ return {
367
+ ok: false,
368
+ result: { ok: false, target, path: file, changed: false, configured: false, rules: [...rules], error: `${file} must contain a JSON object` }
369
+ };
370
+ } catch (error) {
371
+ return {
372
+ ok: false,
373
+ result: {
374
+ ok: false,
375
+ target,
376
+ path: file,
377
+ changed: false,
378
+ configured: false,
379
+ rules: [...rules],
380
+ error: error instanceof Error ? error.message : String(error)
381
+ }
382
+ };
383
+ }
384
+ }
385
+ function isRecord(value) {
386
+ return typeof value === "object" && value !== null && !Array.isArray(value);
387
+ }
388
+
389
+ // src/cli/install-checks.ts
390
+ var import_node_fs2 = __toESM(require("node:fs"));
391
+ var import_node_path3 = __toESM(require("node:path"));
392
+ var import_node_child_process2 = require("node:child_process");
393
+ function runCommand(plan) {
394
+ const result = (0, import_node_child_process2.spawnSync)(plan.command, plan.args, { encoding: "utf8" });
395
+ return { ok: result.status === 0, status: result.status, stderr: result.stderr || "" };
396
+ }
397
+ function pingMcp(runtime) {
398
+ if (!import_node_fs2.default.existsSync(runtime.mcpServer)) return { ok: false, reason: `missing MCP server: ${runtime.mcpServer}` };
399
+ const request = {
400
+ jsonrpc: "2.0",
401
+ id: 1,
402
+ method: "tools/call",
403
+ params: { name: "cadre_project", arguments: { action: "ping" } }
404
+ };
405
+ const result = (0, import_node_child_process2.spawnSync)(runtime.nodePath, [runtime.mcpServer], {
406
+ cwd: runtime.runtimeRoot,
407
+ input: `${JSON.stringify(request)}
408
+ `,
409
+ encoding: "utf8",
410
+ timeout: 3e3
411
+ });
412
+ if (result.status !== 0 && !result.stdout.trim()) return { ok: false, reason: result.stderr || `MCP exited with ${result.status}` };
413
+ const line = result.stdout.split(/\r?\n/).find((entry) => entry.trim());
414
+ if (!line) return { ok: false, reason: "MCP returned no JSON-RPC response" };
415
+ try {
416
+ const parsed = JSON.parse(line);
417
+ if (parsed.error) return { ok: false, reason: parsed.error.message || "MCP returned an error" };
418
+ const text = parsed.result?.content?.[0]?.text;
419
+ const body = text ? JSON.parse(text) : null;
420
+ return body?.data?.ok === true ? { ok: true } : { ok: false, reason: "MCP ping did not return ok:true" };
421
+ } catch (error) {
422
+ return { ok: false, reason: error instanceof Error ? error.message : String(error) };
423
+ }
108
424
  }
425
+ function forbiddenThinPayload(root) {
426
+ return ["assets", "agents", "scripts", "references", "templates"].filter((name) => import_node_fs2.default.existsSync(import_node_path3.default.join(root, name))).map((name) => `${root}/${name}`);
427
+ }
428
+ function pluginConfigFiles(target, pluginRoot) {
429
+ if (target === "codex") {
430
+ return { manifest: import_node_path3.default.join(pluginRoot, ".codex-plugin", "plugin.json"), mcp: import_node_path3.default.join(pluginRoot, ".mcp.json") };
431
+ }
432
+ if (target === "claude") {
433
+ return { manifest: import_node_path3.default.join(pluginRoot, ".claude-plugin", "plugin.json"), mcp: import_node_path3.default.join(pluginRoot, "mcp-config.json") };
434
+ }
435
+ if (target === "copilot") {
436
+ return { manifest: import_node_path3.default.join(pluginRoot, "plugin.json"), mcp: import_node_path3.default.join(pluginRoot, ".mcp.json") };
437
+ }
438
+ return { manifest: import_node_path3.default.join(pluginRoot, "plugin.json"), mcp: import_node_path3.default.join(pluginRoot, "mcp_config.json") };
439
+ }
440
+ function checkMcpConfig(target, file, runtime) {
441
+ const errors = [];
442
+ const config = JSON.parse(import_node_fs2.default.readFileSync(file, "utf8"));
443
+ const server = config.mcpServers?.cadre;
444
+ if (server?.command !== runtime.nodePath) errors.push(`${file} does not point at the current Node runtime`);
445
+ if (server?.args?.[0] !== runtime.mcpServer) errors.push(`${file} does not point at ${runtime.mcpServer}`);
446
+ if (server?.cwd !== runtime.runtimeRoot) errors.push(`${file} has wrong cwd`);
447
+ if (target === "copilot") {
448
+ if (server?.type !== "local") errors.push(`${file} must declare Copilot local MCP type`);
449
+ if (!server?.tools?.includes("*")) errors.push(`${file} must allow Copilot MCP tools`);
450
+ }
451
+ return errors;
452
+ }
453
+ function checkTarget(target, paths, runtime) {
454
+ const errors = [];
455
+ for (const skillRoot of paths.skillRoots) {
456
+ const skill = import_node_path3.default.join(skillRoot, "SKILL.md");
457
+ if (!import_node_fs2.default.existsSync(skill)) errors.push(`missing ${skill}`);
458
+ }
459
+ for (const pluginRoot of paths.pluginRoots) {
460
+ const skill = import_node_path3.default.join(pluginRoot, "skills", "cadre", "SKILL.md");
461
+ if (!import_node_fs2.default.existsSync(skill)) errors.push(`missing ${skill}`);
462
+ const files = pluginConfigFiles(target, pluginRoot);
463
+ if (!import_node_fs2.default.existsSync(files.manifest)) errors.push(`missing ${files.manifest}`);
464
+ if (!import_node_fs2.default.existsSync(files.mcp)) errors.push(`missing ${files.mcp}`);
465
+ errors.push(...forbiddenThinPayload(pluginRoot).map((entry) => `thin plugin contains forbidden payload ${entry}`));
466
+ if (import_node_fs2.default.existsSync(files.mcp)) errors.push(...checkMcpConfig(target, files.mcp, runtime));
467
+ }
468
+ if (paths.marketplaceFile && !import_node_fs2.default.existsSync(paths.marketplaceFile)) errors.push(`missing ${paths.marketplaceFile}`);
469
+ return errors;
470
+ }
471
+ function printPlan(target, paths, commands) {
472
+ if (paths.pluginRoots.length > 0) process.stdout.write(`Cadre ${target} plugin: ${paths.pluginRoots.join(", ")}
473
+ `);
474
+ if (paths.skillRoots.length > 0) process.stdout.write(`Cadre ${target} skill: ${paths.skillRoots.join(", ")}
475
+ `);
476
+ if (paths.marketplaceRoot) process.stdout.write(`Cadre ${target} marketplace: ${paths.marketplaceRoot}
477
+ `);
478
+ for (const command of commands) process.stdout.write(`Would run: ${command.command} ${command.args.join(" ")}
479
+ `);
480
+ }
481
+
482
+ // src/cli/install-writers.ts
483
+ var import_node_fs3 = __toESM(require("node:fs"));
484
+ var import_node_path4 = __toESM(require("node:path"));
485
+ var MARKETPLACE_PLUGIN_SOURCE = "./plugins/cadre";
109
486
  function readPackageMetadata(runtimeRoot) {
110
487
  try {
111
- const json = JSON.parse(import_node_fs.default.readFileSync(import_node_path.default.join(runtimeRoot, "package.json"), "utf8"));
488
+ const json = JSON.parse(import_node_fs3.default.readFileSync(import_node_path4.default.join(runtimeRoot, "package.json"), "utf8"));
112
489
  return {
113
490
  version: typeof json.version === "string" ? json.version : "0.0.0",
114
491
  description: typeof json.description === "string" ? json.description : "MCP-first Cadre workflows.",
@@ -126,9 +503,9 @@ function readPackageMetadata(runtimeRoot) {
126
503
  };
127
504
  }
128
505
  }
129
- function pluginManifest(target, runtime) {
506
+ function baseManifest(runtime) {
130
507
  const metadata = readPackageMetadata(runtime.runtimeRoot);
131
- const base = {
508
+ return {
132
509
  name: PACKAGE_PLUGIN_NAME,
133
510
  version: metadata.version,
134
511
  description: metadata.description,
@@ -139,34 +516,42 @@ function pluginManifest(target, runtime) {
139
516
  keywords: ["cadre", "context-driven-development", "skills", "mcp"],
140
517
  skills: "./skills/"
141
518
  };
142
- if (target === "claude") {
143
- return { ...base, displayName: PACKAGE_DISPLAY_NAME, mcpServers: "./mcp-config.json" };
519
+ }
520
+ function pluginManifest(target, runtime) {
521
+ const base = baseManifest(runtime);
522
+ if (target === "claude") return { ...base, displayName: PACKAGE_DISPLAY_NAME, mcpServers: "./mcp-config.json" };
523
+ if (target === "antigravity") {
524
+ return {
525
+ $schema: "https://antigravity.google/schemas/v1/plugin.json",
526
+ name: PACKAGE_PLUGIN_NAME,
527
+ description: base.description,
528
+ version: base.version
529
+ };
144
530
  }
145
- return {
146
- ...base,
147
- mcpServers: "./.mcp.json",
148
- interface: {
149
- displayName: PACKAGE_DISPLAY_NAME,
150
- shortDescription: "MCP-first planning, tracks, reviews, and packet tools.",
151
- longDescription: "Cadre packages context-driven development workflows for Codex through one global MCP runtime.",
152
- developerName: "Vishal Kumar",
153
- category: "Productivity",
154
- capabilities: ["Read", "Write", "Interactive"],
155
- defaultPrompt: ["Set up this repo with Cadre.", "Show Cadre team status.", "Review the current Cadre track."],
156
- brandColor: "#10A37F"
157
- }
531
+ const mcpServers = "./.mcp.json";
532
+ const codexInterface = {
533
+ displayName: PACKAGE_DISPLAY_NAME,
534
+ shortDescription: "MCP-first planning, tracks, reviews, and packet tools.",
535
+ longDescription: "Cadre packages context-driven development workflows through one global MCP runtime.",
536
+ developerName: "Vishal Kumar",
537
+ category: "Productivity",
538
+ capabilities: ["Read", "Write", "Interactive"],
539
+ defaultPrompt: ["Set up this repo with Cadre.", "Show Cadre team status.", "Review the current Cadre track."],
540
+ brandColor: "#10A37F"
158
541
  };
542
+ return target === "copilot" ? { ...base, mcpServers } : { ...base, mcpServers, interface: codexInterface };
159
543
  }
160
- function mcpConfig(runtime) {
161
- return {
162
- mcpServers: {
163
- cadre: {
164
- command: runtime.nodePath,
165
- args: [runtime.mcpServer],
166
- cwd: runtime.runtimeRoot
167
- }
168
- }
544
+ function mcpConfig(target, runtime) {
545
+ const server = {
546
+ command: runtime.nodePath,
547
+ args: [runtime.mcpServer],
548
+ cwd: runtime.runtimeRoot
169
549
  };
550
+ if (target === "copilot") {
551
+ server.type = "local";
552
+ server.tools = ["*"];
553
+ }
554
+ return { mcpServers: { cadre: server } };
170
555
  }
171
556
  function marketplace(target, runtime) {
172
557
  const metadata = readPackageMetadata(runtime.runtimeRoot);
@@ -198,107 +583,156 @@ function marketplace(target, runtime) {
198
583
  };
199
584
  }
200
585
  function writeJson(file, value) {
201
- import_node_fs.default.mkdirSync(import_node_path.default.dirname(file), { recursive: true });
202
- import_node_fs.default.writeFileSync(file, `${JSON.stringify(value, null, 2)}
586
+ import_node_fs3.default.mkdirSync(import_node_path4.default.dirname(file), { recursive: true });
587
+ import_node_fs3.default.writeFileSync(file, `${JSON.stringify(value, null, 2)}
203
588
  `);
204
589
  }
205
590
  function writeText(file, text) {
206
- import_node_fs.default.mkdirSync(import_node_path.default.dirname(file), { recursive: true });
207
- import_node_fs.default.writeFileSync(file, text.endsWith("\n") ? text : `${text}
591
+ import_node_fs3.default.mkdirSync(import_node_path4.default.dirname(file), { recursive: true });
592
+ import_node_fs3.default.writeFileSync(file, text.endsWith("\n") ? text : `${text}
208
593
  `);
209
594
  }
210
- function writeThinPlugin(target, paths, runtime, skillShim) {
211
- import_node_fs.default.rmSync(paths.pluginRoot, { recursive: true, force: true });
212
- writeText(import_node_path.default.join(paths.pluginRoot, "skills", "cadre", "SKILL.md"), skillShim);
595
+ function writePluginRoot(target, pluginRoot, runtime, skillShim) {
596
+ import_node_fs3.default.rmSync(pluginRoot, { recursive: true, force: true });
597
+ writeText(import_node_path4.default.join(pluginRoot, "skills", "cadre", "SKILL.md"), skillShim);
213
598
  if (target === "codex") {
214
- writeJson(import_node_path.default.join(paths.pluginRoot, ".codex-plugin", "plugin.json"), pluginManifest(target, runtime));
215
- writeJson(import_node_path.default.join(paths.pluginRoot, ".mcp.json"), mcpConfig(runtime));
599
+ writeJson(import_node_path4.default.join(pluginRoot, ".codex-plugin", "plugin.json"), pluginManifest(target, runtime));
600
+ writeJson(import_node_path4.default.join(pluginRoot, ".mcp.json"), mcpConfig(target, runtime));
601
+ } else if (target === "claude") {
602
+ writeJson(import_node_path4.default.join(pluginRoot, ".claude-plugin", "plugin.json"), pluginManifest(target, runtime));
603
+ writeJson(import_node_path4.default.join(pluginRoot, "mcp-config.json"), mcpConfig(target, runtime));
604
+ } else if (target === "copilot") {
605
+ writeJson(import_node_path4.default.join(pluginRoot, "plugin.json"), pluginManifest(target, runtime));
606
+ writeJson(import_node_path4.default.join(pluginRoot, ".mcp.json"), mcpConfig(target, runtime));
216
607
  } else {
217
- writeJson(import_node_path.default.join(paths.pluginRoot, ".claude-plugin", "plugin.json"), pluginManifest(target, runtime));
218
- writeJson(import_node_path.default.join(paths.pluginRoot, "mcp-config.json"), mcpConfig(runtime));
608
+ writeJson(import_node_path4.default.join(pluginRoot, "plugin.json"), pluginManifest(target, runtime));
609
+ writeJson(import_node_path4.default.join(pluginRoot, "mcp_config.json"), mcpConfig(target, runtime));
219
610
  }
220
- writeJson(paths.marketplaceFile, marketplace(target, runtime));
221
611
  }
222
- function installCommands(target, paths, scope) {
223
- if (target === "codex") {
224
- return [
225
- { command: "codex", args: ["plugin", "marketplace", "add", paths.marketplaceRoot] },
226
- { command: "codex", args: ["plugin", "add", "cadre@cadre"] }
227
- ];
612
+ function writeTarget(target, paths, runtime, skillShim) {
613
+ for (const pluginRoot of paths.pluginRoots) writePluginRoot(target, pluginRoot, runtime, skillShim);
614
+ for (const skillRoot of paths.skillRoots) {
615
+ import_node_fs3.default.rmSync(skillRoot, { recursive: true, force: true });
616
+ writeText(import_node_path4.default.join(skillRoot, "SKILL.md"), skillShim);
617
+ }
618
+ if (paths.marketplaceFile && (target === "codex" || target === "claude")) {
619
+ writeJson(paths.marketplaceFile, marketplace(target, runtime));
228
620
  }
621
+ }
622
+ function removeTarget(paths) {
623
+ const roots = /* @__PURE__ */ new Set();
624
+ if (paths.marketplaceRoot) roots.add(paths.marketplaceRoot);
625
+ for (const pluginRoot of paths.pluginRoots) roots.add(pluginRoot);
626
+ for (const skillRoot of paths.skillRoots) roots.add(skillRoot);
627
+ const removed = [];
628
+ for (const root of roots) {
629
+ if (!import_node_fs3.default.existsSync(root)) continue;
630
+ import_node_fs3.default.rmSync(root, { recursive: true, force: true });
631
+ removed.push(root);
632
+ }
633
+ return removed;
634
+ }
635
+
636
+ // src/cli/install.ts
637
+ function usage() {
229
638
  return [
230
- { command: "claude", args: ["plugin", "marketplace", "add", "--scope", scope, paths.marketplaceRoot] },
231
- { command: "claude", args: ["plugin", "install", "--scope", scope, "cadre@cadre"] }
232
- ];
639
+ "Cadre CLI",
640
+ "",
641
+ "Usage:",
642
+ " cadre install [--target codex|claude|copilot|antigravity|all] [--scope user|project|local] [--dry-run] [--check] [--force] [--yes]",
643
+ " cadre uninstall [--target codex|claude|copilot|antigravity|all] [--scope user|project|local] [--dry-run] [--yes]",
644
+ " cadre doctor",
645
+ " cadre help"
646
+ ].join("\n");
233
647
  }
234
- function runCommand(plan) {
235
- const result = (0, import_node_child_process.spawnSync)(plan.command, plan.args, { encoding: "utf8" });
236
- return { ok: result.status === 0, status: result.status, stderr: result.stderr || "" };
648
+ function parseTarget(value) {
649
+ if (!value) throw new Error("--target requires a value");
650
+ if (value === "all") return value;
651
+ if (INSTALL_TARGETS.includes(value)) return value;
652
+ throw new Error("--target must be codex, claude, copilot, antigravity, or all");
237
653
  }
238
- function assertNoThinPluginPayload(paths) {
239
- const forbidden = ["assets", "agents", "scripts"].filter((name) => import_node_fs.default.existsSync(import_node_path.default.join(paths.pluginRoot, name)));
240
- return forbidden.map((name) => `${paths.pluginRoot}/${name}`);
654
+ function parseScope(value) {
655
+ if (value === "user" || value === "project" || value === "local") return value;
656
+ throw new Error("--scope must be user, project, or local");
241
657
  }
242
- function pingMcp(runtime) {
243
- if (!import_node_fs.default.existsSync(runtime.mcpServer)) return { ok: false, reason: `missing MCP server: ${runtime.mcpServer}` };
244
- const request = {
245
- jsonrpc: "2.0",
246
- id: 1,
247
- method: "tools/call",
248
- params: { name: "cadre_project", arguments: { action: "ping" } }
658
+ function parseInstall(argv) {
659
+ const parsed = {
660
+ target: "auto",
661
+ scope: "user",
662
+ dryRun: false,
663
+ check: false,
664
+ force: false,
665
+ yes: false,
666
+ cadreHome: process.env.CADRE_HOME || import_node_path5.default.join(import_node_os3.default.homedir(), ".cadre")
249
667
  };
250
- const result = (0, import_node_child_process.spawnSync)(runtime.nodePath, [runtime.mcpServer], {
251
- cwd: runtime.runtimeRoot,
252
- input: `${JSON.stringify(request)}
253
- `,
254
- encoding: "utf8",
255
- timeout: 3e3
256
- });
257
- if (result.status !== 0 && !result.stdout.trim()) return { ok: false, reason: result.stderr || `MCP exited with ${result.status}` };
258
- const line = result.stdout.split(/\r?\n/).find((entry) => entry.trim());
259
- if (!line) return { ok: false, reason: "MCP returned no JSON-RPC response" };
260
- try {
261
- const parsed = JSON.parse(line);
262
- if (parsed.error) return { ok: false, reason: parsed.error.message || "MCP returned an error" };
263
- const text = parsed.result?.content?.[0]?.text;
264
- const body = text ? JSON.parse(text) : null;
265
- return body?.data?.ok === true ? { ok: true } : { ok: false, reason: "MCP ping did not return ok:true" };
266
- } catch (error) {
267
- return { ok: false, reason: error instanceof Error ? error.message : String(error) };
668
+ for (let index = 0; index < argv.length; index += 1) {
669
+ const arg = argv[index];
670
+ if (arg === "--dry-run") parsed.dryRun = true;
671
+ else if (arg === "--check") parsed.check = true;
672
+ else if (arg === "--force") parsed.force = true;
673
+ else if (arg === "--yes" || arg === "-y") parsed.yes = true;
674
+ else if (arg === "--target") {
675
+ parsed.target = parseTarget(argv[index + 1]);
676
+ index += 1;
677
+ } else if (arg === "--scope") {
678
+ parsed.scope = parseScope(argv[index + 1]);
679
+ index += 1;
680
+ } else if (arg === "--home") {
681
+ const value = argv[index + 1];
682
+ if (!value) throw new Error("--home requires a path");
683
+ parsed.cadreHome = import_node_path5.default.resolve(value);
684
+ index += 1;
685
+ } else {
686
+ throw new Error(`Unknown install option: ${arg}`);
687
+ }
268
688
  }
689
+ return parsed;
269
690
  }
270
- function checkTarget(target, paths, runtime) {
271
- const errors = [];
272
- const skill = import_node_path.default.join(paths.pluginRoot, "skills", "cadre", "SKILL.md");
273
- if (!import_node_fs.default.existsSync(skill)) errors.push(`missing ${skill}`);
274
- const manifest = target === "codex" ? import_node_path.default.join(paths.pluginRoot, ".codex-plugin", "plugin.json") : import_node_path.default.join(paths.pluginRoot, ".claude-plugin", "plugin.json");
275
- const mcp = target === "codex" ? import_node_path.default.join(paths.pluginRoot, ".mcp.json") : import_node_path.default.join(paths.pluginRoot, "mcp-config.json");
276
- if (!import_node_fs.default.existsSync(manifest)) errors.push(`missing ${manifest}`);
277
- if (!import_node_fs.default.existsSync(mcp)) errors.push(`missing ${mcp}`);
278
- errors.push(...assertNoThinPluginPayload(paths).map((entry) => `thin plugin contains forbidden payload ${entry}`));
279
- if (import_node_fs.default.existsSync(mcp)) {
280
- const config = JSON.parse(import_node_fs.default.readFileSync(mcp, "utf8"));
281
- const server = config.mcpServers?.cadre;
282
- if (server?.command !== runtime.nodePath) errors.push(`${mcp} does not point at the current Node runtime`);
283
- if (server?.args?.[0] !== runtime.mcpServer) errors.push(`${mcp} does not point at ${runtime.mcpServer}`);
284
- if (server?.cwd !== runtime.runtimeRoot) errors.push(`${mcp} has wrong cwd`);
691
+ function printApprovalResult(target, path6, configured) {
692
+ if (configured) {
693
+ process.stdout.write(`Cadre ${target} MCP tool approvals are configured in ${path6}
694
+ `);
695
+ } else {
696
+ process.stdout.write(`Cadre ${target} MCP tools may prompt on first use; no approval file was changed.
697
+ `);
285
698
  }
286
- return errors;
287
699
  }
288
- function printPlan(target, paths, commands) {
289
- process.stdout.write(`Cadre ${target} plugin: ${paths.pluginRoot}
700
+ function installedNoun(paths) {
701
+ return paths.pluginRoots.length > 0 ? "plugin" : "skill";
702
+ }
703
+ function pathsExist(paths) {
704
+ return Boolean(
705
+ paths.marketplaceRoot && import_node_fs4.default.existsSync(paths.marketplaceRoot) || paths.pluginRoots.some((root) => import_node_fs4.default.existsSync(root)) || paths.skillRoots.some((root) => import_node_fs4.default.existsSync(root))
706
+ );
707
+ }
708
+ function selectedUninstallTargets(options) {
709
+ if (options.target !== "auto" && options.target !== "all") return [options.target];
710
+ if (options.target === "all") return [...INSTALL_TARGETS];
711
+ return INSTALL_TARGETS.filter(
712
+ (target) => commandExists(target === "antigravity" ? "agy" : target) || pathsExist(targetPaths(options.cadreHome, target, options.scope))
713
+ );
714
+ }
715
+ function printUninstallPlan(target, paths, commands) {
716
+ if (paths.marketplaceRoot) process.stdout.write(`Would remove: ${paths.marketplaceRoot}
290
717
  `);
291
- process.stdout.write(`Cadre ${target} marketplace: ${paths.marketplaceRoot}
718
+ for (const pluginRoot of paths.pluginRoots) process.stdout.write(`Would remove: ${pluginRoot}
719
+ `);
720
+ for (const skillRoot of paths.skillRoots) process.stdout.write(`Would remove: ${skillRoot}
292
721
  `);
293
722
  for (const command of commands) process.stdout.write(`Would run: ${command.command} ${command.args.join(" ")}
294
723
  `);
724
+ if (!pathsExist(paths) && commands.length === 0) process.stdout.write(`No Cadre ${target} files or native uninstall commands found.
725
+ `);
726
+ }
727
+ function missingInstallCommandIsWarning(options, target, optional) {
728
+ return optional === true || options.target === "all" && target === "copilot";
295
729
  }
296
730
  function runInstall(argv, context) {
297
731
  const options = parseInstall(argv);
298
732
  const runtime = runtimePaths();
299
733
  const targets = selectedTargets(options);
300
734
  if (targets.length === 0) {
301
- process.stderr.write("No supported client detected. Install Codex or Claude, or pass --target codex|claude.\n");
735
+ process.stderr.write("No supported client detected. Install Codex, Claude, Copilot, or Antigravity, or pass --target codex|claude|copilot|antigravity.\n");
302
736
  return 1;
303
737
  }
304
738
  const ping = pingMcp(runtime);
@@ -309,44 +743,101 @@ function runInstall(argv, context) {
309
743
  }
310
744
  let ok = true;
311
745
  for (const target of targets) {
312
- const paths = targetPaths(options.cadreHome, target);
746
+ let targetOk = true;
747
+ const paths = targetPaths(options.cadreHome, target, options.scope);
313
748
  const commands = installCommands(target, paths, options.scope);
314
749
  if (options.dryRun) {
315
750
  printPlan(target, paths, commands);
751
+ process.stdout.write(`Would configure: ${approvalSummary(target)}
752
+ `);
316
753
  continue;
317
754
  }
318
- if (!options.check) writeThinPlugin(target, paths, runtime, context.skillShim);
755
+ if (!options.check) writeTarget(target, paths, runtime, context.skillShim);
319
756
  const errors = checkTarget(target, paths, runtime);
757
+ if (!options.check) {
758
+ const approvals = bootstrapClientApprovals(target);
759
+ if (!approvals.ok) errors.push(`${target} approval bootstrap failed: ${approvals.error || approvals.path}`);
760
+ }
761
+ const approvalCheck = checkClientApprovals(target);
762
+ if (!approvalCheck.ok) errors.push(`${target} approval check failed: ${approvalCheck.error || approvalCheck.path}`);
320
763
  if (errors.length > 0) {
321
764
  ok = false;
765
+ targetOk = false;
322
766
  for (const error of errors) process.stderr.write(`${error}
323
767
  `);
324
768
  continue;
325
769
  }
326
770
  if (options.check) {
327
- process.stdout.write(`Cadre ${target} plugin is installed and points at ${runtime.mcpServer}
328
- `);
329
- continue;
330
- }
331
- if (!commandExists(target)) {
332
- ok = false;
333
- process.stderr.write(`${target} command not found; plugin files were written but native registration was skipped.
771
+ process.stdout.write(`Cadre ${target} ${installedNoun(paths)} is installed and points at ${runtime.mcpServer}
334
772
  `);
773
+ printApprovalResult(target, approvalCheck.path, approvalCheck.configured);
335
774
  continue;
336
775
  }
337
776
  for (const command of commands) {
777
+ if (!commandExists(command.command)) {
778
+ const message = `${command.command} command not found; plugin files were written but native registration was skipped.
779
+ `;
780
+ if (missingInstallCommandIsWarning(options, target, command.optional)) process.stderr.write(message);
781
+ else {
782
+ targetOk = false;
783
+ ok = false;
784
+ process.stderr.write(message);
785
+ }
786
+ continue;
787
+ }
338
788
  const result = runCommand(command);
339
789
  if (!result.ok) {
790
+ targetOk = false;
340
791
  ok = false;
341
792
  process.stderr.write(`${command.command} ${command.args.join(" ")} failed: ${result.stderr}
342
793
  `);
343
794
  }
344
795
  }
345
- if (ok) process.stdout.write(`Installed Cadre ${target} plugin through ${paths.marketplaceRoot}
796
+ if (targetOk) {
797
+ process.stdout.write(`Installed Cadre ${target} ${installedNoun(paths)} through ${paths.primaryRoot}
346
798
  `);
799
+ printApprovalResult(target, approvalCheck.path, approvalCheck.configured);
800
+ }
347
801
  }
348
802
  return ok ? 0 : 1;
349
803
  }
804
+ function runUninstall(argv) {
805
+ const options = parseInstall(argv);
806
+ const targets = selectedUninstallTargets(options);
807
+ if (targets.length === 0) {
808
+ process.stderr.write("No Cadre client install found. Pass --target codex|claude|copilot|antigravity to remove a specific generated target.\n");
809
+ return 1;
810
+ }
811
+ for (const target of targets) {
812
+ const paths = targetPaths(options.cadreHome, target, options.scope);
813
+ const commands = uninstallCommands(target, paths, options.scope);
814
+ if (options.dryRun) {
815
+ printUninstallPlan(target, paths, commands);
816
+ continue;
817
+ }
818
+ for (const command of commands) {
819
+ if (!commandExists(command.command)) {
820
+ process.stderr.write(`${command.command} command not found; removing generated Cadre ${target} files only.
821
+ `);
822
+ continue;
823
+ }
824
+ const result = runCommand(command);
825
+ if (!result.ok) {
826
+ process.stderr.write(`${command.command} ${command.args.join(" ")} failed; continuing local cleanup: ${result.stderr}
827
+ `);
828
+ }
829
+ }
830
+ const removed = removeTarget(paths);
831
+ if (removed.length > 0) {
832
+ process.stdout.write(`Uninstalled Cadre ${target} ${installedNoun(paths)} and removed ${removed.join(", ")}
833
+ `);
834
+ } else {
835
+ process.stdout.write(`No generated Cadre ${target} files found to remove.
836
+ `);
837
+ }
838
+ }
839
+ return 0;
840
+ }
350
841
  function runDoctor() {
351
842
  const runtime = runtimePaths();
352
843
  const ping = pingMcp(runtime);
@@ -364,6 +855,7 @@ async function runCli(argv, context) {
364
855
  const command = argv[0] || "help";
365
856
  let code = 0;
366
857
  if (command === "install") code = runInstall(argv.slice(1), context);
858
+ else if (command === "uninstall" || command === "remove") code = runUninstall(argv.slice(1));
367
859
  else if (command === "doctor") code = runDoctor();
368
860
  else if (command === "help" || command === "--help" || command === "-h") process.stdout.write(`${usage()}
369
861
  `);