cadre-ai 2.2.0 → 3.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 (79) hide show
  1. package/.claude-plugin/plugin.json +10 -0
  2. package/.codex-plugin/plugin.json +19 -0
  3. package/.mcp.codex.json +9 -0
  4. package/.mcp.json +8 -0
  5. package/LICENSE +21 -202
  6. package/README.md +353 -134
  7. package/agents/cadre-phase-worker.md +17 -0
  8. package/agents/cadre-task-worker.md +16 -0
  9. package/dist/cadre-cli.mjs +2756 -0
  10. package/dist/cadre-mcp.mjs +33680 -0
  11. package/marketplace/claude.json +16 -0
  12. package/marketplace/codex.json +20 -0
  13. package/package.json +36 -32
  14. package/skills/archive/SKILL.md +28 -0
  15. package/skills/archive/agents/openai.yaml +4 -0
  16. package/skills/create/SKILL.md +33 -0
  17. package/skills/create/agents/openai.yaml +4 -0
  18. package/skills/implement/SKILL.md +91 -0
  19. package/skills/implement/agents/openai.yaml +4 -0
  20. package/skills/refresh/SKILL.md +18 -0
  21. package/skills/refresh/agents/openai.yaml +4 -0
  22. package/skills/revert/SKILL.md +20 -0
  23. package/skills/revert/agents/openai.yaml +4 -0
  24. package/skills/review/SKILL.md +32 -0
  25. package/skills/review/agents/openai.yaml +4 -0
  26. package/skills/revise/SKILL.md +32 -0
  27. package/skills/revise/agents/openai.yaml +4 -0
  28. package/skills/status/SKILL.md +21 -0
  29. package/skills/status/agents/openai.yaml +4 -0
  30. package/skills/track/SKILL.md +33 -0
  31. package/skills/track/agents/openai.yaml +4 -0
  32. package/skills/wisp/SKILL.md +16 -0
  33. package/skills/wisp/agents/openai.yaml +4 -0
  34. package/templates/v1/init/archive/.gitkeep +1 -0
  35. package/templates/v1/init/guidelines.md +25 -0
  36. package/templates/v1/init/operations/.gitkeep +1 -0
  37. package/templates/v1/init/patterns/index.md +6 -0
  38. package/templates/v1/init/product.md +30 -0
  39. package/templates/v1/init/project.json +26 -0
  40. package/templates/v1/init/refreshes/.gitkeep +1 -0
  41. package/templates/v1/init/styleguides/general.md +14 -0
  42. package/templates/v1/init/styleguides/language.md +21 -0
  43. package/templates/v1/init/tech-stack.md +21 -0
  44. package/templates/v1/init/tracks/.gitkeep +1 -0
  45. package/templates/v1/init/tracks.md +6 -0
  46. package/templates/v1/init/workflow.md +163 -0
  47. package/templates/v1/project/archive-operation.json +15 -0
  48. package/templates/v1/project/pattern.md +20 -0
  49. package/templates/v1/project/refresh-operation.json +14 -0
  50. package/templates/v1/project/refresh.md +21 -0
  51. package/templates/v1/styleguides/dart.md +27 -0
  52. package/templates/v1/styleguides/flutter.md +27 -0
  53. package/templates/v1/styleguides/go.md +29 -0
  54. package/templates/v1/styleguides/gradle.md +28 -0
  55. package/templates/v1/styleguides/html-css.md +39 -0
  56. package/templates/v1/styleguides/index.md +27 -0
  57. package/templates/v1/styleguides/java.md +27 -0
  58. package/templates/v1/styleguides/javascript.md +27 -0
  59. package/templates/v1/styleguides/kotlin.md +26 -0
  60. package/templates/v1/styleguides/maven.md +28 -0
  61. package/templates/v1/styleguides/python.md +27 -0
  62. package/templates/v1/styleguides/react.md +28 -0
  63. package/templates/v1/styleguides/swift.md +27 -0
  64. package/templates/v1/styleguides/swiftui.md +27 -0
  65. package/templates/v1/styleguides/typescript.md +26 -0
  66. package/templates/v1/track/bug.md +14 -0
  67. package/templates/v1/track/execution.json +18 -0
  68. package/templates/v1/track/learning.md +39 -0
  69. package/templates/v1/track/plan.md +39 -0
  70. package/templates/v1/track/revert-operation.json +13 -0
  71. package/templates/v1/track/revise-operation.json +14 -0
  72. package/templates/v1/track/revision.md +36 -0
  73. package/templates/v1/track/spec.md +38 -0
  74. package/templates/v1/track/state.json +25 -0
  75. package/scripts/cadre-cli.js +0 -1076
  76. package/scripts/cadre-core.js +0 -15240
  77. package/scripts/cadre-lsp-review.js +0 -1194
  78. package/scripts/cadre-lsp-setup.js +0 -599
  79. package/scripts/mcp/cadre-server.js +0 -19013
@@ -1,1076 +0,0 @@
1
- #!/usr/bin/env node
2
- // AUTO-GENERATED by pnpm build from src/*.ts -- do not edit by hand.
3
- // Edit TypeScript sources under src/ instead.
4
- const __CADRE_SKILL_SHIM__ = "---\nname: cadre\ndescription: Packet-led context-driven development for Cadre projects and workflows.\n---\n\n# Cadre\n\nCall `cadre_workflow` directly with one nested request:\n`{root, workflow, input, execute, approval}`. The call itself verifies Cadre\nand resolves the root. Follow the returned `decision` and load only returned\nresource URIs. A non-null `next` is the sole typed continuation: invoke exactly\n`next.tool` with `next.arguments`, at most once for that packet. It is the sole\nimmediate single-agent Cadre continuation. The only typed callbacks outside\n`next` are `decision.required.write_back`, used after collecting the requested\nexternal provider evidence, and each parallel worker's\n`data.workers[].dispatch.record_finish_packet`, used once with that worker's\nresult. While workers remain incomplete or need recovery, Cadre reissues their\nexact callbacks under `data.worker_callbacks[].record_finish_packet`. Never\ninfer a callback from prose or hardcode later merge or cleanup actions; a\nsubsequent packet returns those operations through `next` only when safe.\n\nUse `cadre_action` only as `{root, action, input, execute}` for the namespaced\naction returned by a packet. Use `cadre_read` only as `{uri}` for a relevant\nresource. Cadre owns control-plane, approval, provider, worker, merge, and\ngenerated-projection state. Never recreate that state with shell commands or\ntreat Markdown projections as canonical.\n\nSend `approval` only after explicit user approval of the current human-facing\ndocument. Its canonical JSON/JSONL and generated projection are one immutable\nreview pair and never receive separate approvals. `execute:true` authorizes a\nmutation or side effect; it is not document approval. If a packet is blocked,\nreport its error or requested narrowing; do not truncate or invent required\nproject-skill rules.\n";
5
- const __CADRE_COMMAND_SKILL_TEMPLATE__ = "---\nname: \"{{command}}\"\ndescription: \"Use when the user invokes {{command}} or asks to start or continue the Cadre {{workflow}} workflow.\"\n---\n\n# {{command}}\n\nStart or continue Cadre's `{{workflow}}` workflow through the packet-owned MCP\ncontract.\n\n1. Call `cadre_workflow` with one nested request containing the resolved\n project `root`, `workflow:\"{{workflow}}\"`, workflow-specific `input`, and\n `execute:false`. Keep workflow fields inside `input` and omit `approval` on\n the initial call.\n2. Follow the returned `decision`. If `next` is non-null, invoke exactly\n `next.tool` with `next.arguments` once for that packet.\n3. Use `cadre_action` and `cadre_read` only when the packet returns that exact\n action or resource. Outside `next`, use only an exact returned\n `decision.required.write_back`, `data.workers[].dispatch.record_finish_packet`,\n or `data.worker_callbacks[].record_finish_packet`; never invent merge or\n cleanup callbacks.\n4. Send `approval` only after explicit user approval of the current reviewed\n document and its canonical pair. Treat `execute:true` as mutation\n authorization, not approval.\n\nDo not infer later actions from prose, edit Cadre-owned state manually, or treat\nMarkdown projections as canonical input. If required project-skill rules do not\nfit, report the requested narrowing instead of truncating them.\n";
6
- const __CADRE_WORKFLOW_COMMANDS__ = ["setup","newtrack","implement","debug","status","validate","flag","revise","review","ship","land","handoff","archive","release","refresh","revert","formula","artifacts","skill"];
7
- "use strict";
8
- var __create = Object.create;
9
- var __defProp = Object.defineProperty;
10
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
- var __getOwnPropNames = Object.getOwnPropertyNames;
12
- var __getProtoOf = Object.getPrototypeOf;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __copyProps = (to, from, except, desc) => {
15
- if (from && typeof from === "object" || typeof from === "function") {
16
- for (let key of __getOwnPropNames(from))
17
- if (!__hasOwnProp.call(to, key) && key !== except)
18
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
- mod
29
- ));
30
-
31
- // src/cli/install.ts
32
- var import_node_fs4 = __toESM(require("node:fs"));
33
- var import_node_os3 = __toESM(require("node:os"));
34
- var import_node_path5 = __toESM(require("node:path"));
35
-
36
- // src/cli/client-approvals.ts
37
- var import_node_fs = __toESM(require("node:fs"));
38
- var import_node_os2 = __toESM(require("node:os"));
39
- var import_node_path2 = __toESM(require("node:path"));
40
-
41
- // src/cli/install-targets.ts
42
- var import_node_os = __toESM(require("node:os"));
43
- var import_node_path = __toESM(require("node:path"));
44
- var import_node_child_process = require("node:child_process");
45
- var INSTALL_TARGETS = ["codex", "claude", "copilot", "antigravity"];
46
- var TARGET_COMMANDS = {
47
- codex: "codex",
48
- claude: "claude",
49
- copilot: "copilot",
50
- antigravity: "agy"
51
- };
52
- var PACKAGE_PLUGIN_NAME = "cadre";
53
- var PACKAGE_DISPLAY_NAME = "Cadre";
54
- function runtimePaths() {
55
- const runtimeRoot = import_node_path.default.resolve(__dirname, "..");
56
- return {
57
- runtimeRoot,
58
- nodePath: process.execPath,
59
- mcpServer: import_node_path.default.join(runtimeRoot, "scripts", "mcp", "cadre-server.js")
60
- };
61
- }
62
- function commandExists(command) {
63
- const result = process.platform === "win32" ? (0, import_node_child_process.spawnSync)("where", [command], { stdio: "ignore" }) : (0, import_node_child_process.spawnSync)("which", [command], { stdio: "ignore" });
64
- return result.status === 0;
65
- }
66
- function selectedTargets(options) {
67
- if (options.target !== "auto" && options.target !== "all") return [options.target];
68
- if (options.target === "all") return [...INSTALL_TARGETS];
69
- return INSTALL_TARGETS.filter((target) => commandExists(TARGET_COMMANDS[target]));
70
- }
71
- function antigravityCliHome() {
72
- 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");
73
- }
74
- function antigravityIdeHome() {
75
- 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");
76
- }
77
- function targetPaths(home, target, scope, cwd = process.cwd()) {
78
- if (target === "copilot" && scope !== "user") {
79
- const skillRoot = import_node_path.default.join(cwd, ".github", "skills", PACKAGE_PLUGIN_NAME);
80
- return { primaryRoot: skillRoot, pluginRoots: [], skillRoots: [skillRoot] };
81
- }
82
- if (target === "antigravity") {
83
- if (scope !== "user") {
84
- const pluginRoot2 = import_node_path.default.join(cwd, ".agents", "plugins", PACKAGE_PLUGIN_NAME);
85
- return { primaryRoot: pluginRoot2, pluginRoots: [pluginRoot2], skillRoots: [] };
86
- }
87
- const cliPlugin = import_node_path.default.join(antigravityCliHome(), "plugins", PACKAGE_PLUGIN_NAME);
88
- const idePlugin = import_node_path.default.join(antigravityIdeHome(), "plugins", PACKAGE_PLUGIN_NAME);
89
- return { primaryRoot: cliPlugin, pluginRoots: [cliPlugin, idePlugin], skillRoots: [] };
90
- }
91
- const marketplaceRoot = import_node_path.default.join(home, "marketplaces", target);
92
- const pluginRoot = import_node_path.default.join(marketplaceRoot, "plugins", PACKAGE_PLUGIN_NAME);
93
- 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;
94
- const paths = {
95
- primaryRoot: pluginRoot,
96
- marketplaceRoot,
97
- pluginRoots: [pluginRoot],
98
- skillRoots: []
99
- };
100
- if (marketplaceFile) paths.marketplaceFile = marketplaceFile;
101
- return paths;
102
- }
103
- function installCommands(target, paths, scope) {
104
- if (target === "codex") {
105
- return [
106
- { command: "codex", args: ["plugin", "marketplace", "add", paths.marketplaceRoot || ""] },
107
- { command: "codex", args: ["plugin", "add", "cadre@cadre"] }
108
- ];
109
- }
110
- if (target === "claude") {
111
- return [
112
- { command: "claude", args: ["plugin", "marketplace", "add", "--scope", scope, paths.marketplaceRoot || ""] },
113
- { command: "claude", args: ["plugin", "install", "--scope", scope, "cadre@cadre"] },
114
- { command: "claude", args: ["plugin", "update", "--scope", scope, "cadre@cadre"] }
115
- ];
116
- }
117
- if (target === "copilot" && scope === "user") {
118
- return [{ command: "copilot", args: ["plugin", "install", paths.primaryRoot] }];
119
- }
120
- if (target === "antigravity" && scope === "user") {
121
- return [{ command: "agy", args: ["plugin", "install", paths.primaryRoot], optional: true }];
122
- }
123
- return [];
124
- }
125
- function uninstallCommands(target, paths, scope) {
126
- if (target === "codex") {
127
- return [
128
- { command: "codex", args: ["plugin", "remove", "cadre@cadre"], optional: true },
129
- { command: "codex", args: ["plugin", "marketplace", "remove", PACKAGE_PLUGIN_NAME], optional: true }
130
- ];
131
- }
132
- if (target === "claude") {
133
- return [
134
- { command: "claude", args: ["plugin", "uninstall", "--scope", scope, "--yes", "cadre@cadre"], optional: true },
135
- { command: "claude", args: ["plugin", "marketplace", "remove", "--scope", scope, PACKAGE_PLUGIN_NAME], optional: true }
136
- ];
137
- }
138
- if (target === "copilot" && scope === "user") {
139
- return [{ command: "copilot", args: ["plugin", "uninstall", paths.primaryRoot], optional: true }];
140
- }
141
- if (target === "antigravity" && scope === "user") {
142
- return [{ command: "agy", args: ["plugin", "uninstall", PACKAGE_PLUGIN_NAME], optional: true }];
143
- }
144
- return [];
145
- }
146
-
147
- // src/cli/client-approvals.ts
148
- var CADRE_MCP_TOOLS = [
149
- "cadre_workflow",
150
- "cadre_action",
151
- "cadre_read"
152
- ];
153
- var CLAUDE_CADRE_ALLOW_RULES = [
154
- "mcp__plugin_cadre_cadre__*",
155
- "mcp__cadre__*"
156
- ];
157
- var ANTIGRAVITY_CADRE_ALLOW_RULES = [
158
- "mcp(cadre/*)"
159
- ];
160
- function approvalConfigPath(target) {
161
- if (target === "codex") {
162
- return import_node_path2.default.join(process.env.CODEX_HOME || import_node_path2.default.join(import_node_os2.default.homedir(), ".codex"), "config.toml");
163
- }
164
- if (target === "claude") {
165
- 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");
166
- }
167
- if (target === "antigravity") return import_node_path2.default.join(antigravityCliHome(), "settings.json");
168
- return import_node_path2.default.join(process.env.COPILOT_HOME || import_node_path2.default.join(import_node_os2.default.homedir(), ".copilot"), "permissions-config.json");
169
- }
170
- function bootstrapClientApprovals(target) {
171
- if (target === "codex") return bootstrapCodexApprovals();
172
- if (target === "claude") return bootstrapClaudeApprovals();
173
- if (target === "antigravity") return bootstrapAntigravityApprovals();
174
- return copilotPromptResult();
175
- }
176
- function checkClientApprovals(target) {
177
- if (target === "codex") return checkCodexApprovals();
178
- if (target === "claude") return checkClaudeApprovals();
179
- if (target === "antigravity") return checkAntigravityApprovals();
180
- return copilotPromptResult();
181
- }
182
- function approvalSummary(target) {
183
- const file = approvalConfigPath(target);
184
- if (target === "codex") return `Cadre codex MCP tool approvals: ${file}`;
185
- if (target === "claude") return `Cadre claude MCP tool approvals: ${file}`;
186
- if (target === "antigravity") return `Cadre antigravity CLI MCP allow rule: ${file}`;
187
- return "Cadre copilot MCP tools may prompt on first use; no approval file is edited";
188
- }
189
- function codexToolSection(tool) {
190
- return `[plugins."cadre@cadre".mcp_servers.cadre.tools.${tool}]`;
191
- }
192
- function codexApprovalSnippet(tool) {
193
- return `${codexToolSection(tool)}
194
- approval_mode = "approve"
195
- `;
196
- }
197
- function bootstrapCodexApprovals() {
198
- const file = approvalConfigPath("codex");
199
- let text = "";
200
- if (import_node_fs.default.existsSync(file)) text = import_node_fs.default.readFileSync(file, "utf8");
201
- const before = text;
202
- for (const tool of CADRE_MCP_TOOLS) text = upsertCodexApproval(text, tool);
203
- if (text !== before) {
204
- import_node_fs.default.mkdirSync(import_node_path2.default.dirname(file), { recursive: true });
205
- import_node_fs.default.writeFileSync(file, text);
206
- }
207
- return { ok: true, target: "codex", path: file, changed: text !== before, configured: true, rules: [...CADRE_MCP_TOOLS] };
208
- }
209
- function checkCodexApprovals() {
210
- const file = approvalConfigPath("codex");
211
- if (!import_node_fs.default.existsSync(file)) {
212
- return { ok: false, target: "codex", path: file, changed: false, configured: false, rules: [...CADRE_MCP_TOOLS], error: `missing ${file}` };
213
- }
214
- const text = import_node_fs.default.readFileSync(file, "utf8");
215
- const missing = CADRE_MCP_TOOLS.filter((tool) => !codexToolApproved(text, tool));
216
- const result = {
217
- ok: missing.length === 0,
218
- target: "codex",
219
- path: file,
220
- changed: false,
221
- configured: missing.length === 0,
222
- rules: missing.length === 0 ? [...CADRE_MCP_TOOLS] : missing
223
- };
224
- if (missing.length > 0) result.error = `missing Codex Cadre tool approvals: ${missing.join(", ")}`;
225
- return result;
226
- }
227
- function upsertCodexApproval(text, tool) {
228
- let next = text.endsWith("\n") || text.length === 0 ? text : `${text}
229
- `;
230
- const header = codexToolSection(tool);
231
- const lines = next.split("\n");
232
- const start = lines.findIndex((line) => line.trim() === header);
233
- if (start === -1) {
234
- const spacer = next.trim().length > 0 && !next.endsWith("\n\n") ? "\n" : "";
235
- return `${next}${spacer}${codexApprovalSnippet(tool)}`;
236
- }
237
- let end = lines.length;
238
- for (let index = start + 1; index < lines.length; index += 1) {
239
- if (lines[index]?.trim().startsWith("[")) {
240
- end = index;
241
- break;
242
- }
243
- }
244
- for (let index = start + 1; index < end; index += 1) {
245
- if (/^\s*approval_mode\s*=/.test(lines[index] || "")) {
246
- lines[index] = 'approval_mode = "approve"';
247
- return lines.join("\n");
248
- }
249
- }
250
- lines.splice(start + 1, 0, 'approval_mode = "approve"');
251
- return lines.join("\n");
252
- }
253
- function codexToolApproved(text, tool) {
254
- const lines = text.split(/\r?\n/);
255
- const header = codexToolSection(tool);
256
- const start = lines.findIndex((line) => line.trim() === header);
257
- if (start === -1) return false;
258
- for (let index = start + 1; index < lines.length; index += 1) {
259
- const line = lines[index]?.trim() || "";
260
- if (line.startsWith("[")) return false;
261
- if (line === 'approval_mode = "approve"' || line === "approval_mode = 'approve'") return true;
262
- }
263
- return false;
264
- }
265
- function bootstrapClaudeApprovals() {
266
- const file = approvalConfigPath("claude");
267
- const parsed = readClaudeSettings(file);
268
- if (!parsed.ok) return parsed.result;
269
- const settings = parsed.settings;
270
- const permissions = isRecord(settings.permissions) ? settings.permissions : {};
271
- const currentAllow = Array.isArray(permissions.allow) ? permissions.allow.filter((item) => typeof item === "string") : [];
272
- const nextAllow = [...currentAllow];
273
- for (const rule of CLAUDE_CADRE_ALLOW_RULES) {
274
- if (!nextAllow.includes(rule)) nextAllow.push(rule);
275
- }
276
- const changed = nextAllow.length !== currentAllow.length || !isRecord(settings.permissions) || !Array.isArray(permissions.allow);
277
- if (changed) {
278
- settings.permissions = { ...permissions, allow: nextAllow };
279
- import_node_fs.default.mkdirSync(import_node_path2.default.dirname(file), { recursive: true });
280
- import_node_fs.default.writeFileSync(file, `${JSON.stringify(settings, null, 2)}
281
- `);
282
- }
283
- return { ok: true, target: "claude", path: file, changed, configured: true, rules: [...CLAUDE_CADRE_ALLOW_RULES] };
284
- }
285
- function checkClaudeApprovals() {
286
- const file = approvalConfigPath("claude");
287
- const parsed = readClaudeSettings(file);
288
- if (!parsed.ok) return parsed.result;
289
- const permissions = isRecord(parsed.settings.permissions) ? parsed.settings.permissions : {};
290
- const allow = Array.isArray(permissions.allow) ? permissions.allow.filter((item) => typeof item === "string") : [];
291
- const missing = CLAUDE_CADRE_ALLOW_RULES.filter((rule) => !allow.includes(rule));
292
- const result = {
293
- ok: missing.length === 0,
294
- target: "claude",
295
- path: file,
296
- changed: false,
297
- configured: missing.length === 0,
298
- rules: missing.length === 0 ? [...CLAUDE_CADRE_ALLOW_RULES] : missing
299
- };
300
- if (missing.length > 0) result.error = `missing Claude Cadre tool allow rules: ${missing.join(", ")}`;
301
- return result;
302
- }
303
- function bootstrapAntigravityApprovals() {
304
- const file = approvalConfigPath("antigravity");
305
- const parsed = readJsonSettings(file, "antigravity", ANTIGRAVITY_CADRE_ALLOW_RULES);
306
- if (!parsed.ok) return parsed.result;
307
- const settings = parsed.settings;
308
- const permissions = isRecord(settings.permissions) ? settings.permissions : {};
309
- const currentAllow = Array.isArray(permissions.allow) ? permissions.allow.filter((item) => typeof item === "string") : [];
310
- const nextAllow = [...currentAllow];
311
- for (const rule of ANTIGRAVITY_CADRE_ALLOW_RULES) {
312
- if (!nextAllow.includes(rule)) nextAllow.push(rule);
313
- }
314
- const changed = nextAllow.length !== currentAllow.length || !isRecord(settings.permissions) || !Array.isArray(permissions.allow);
315
- if (changed) {
316
- settings.permissions = { ...permissions, allow: nextAllow };
317
- import_node_fs.default.mkdirSync(import_node_path2.default.dirname(file), { recursive: true });
318
- import_node_fs.default.writeFileSync(file, `${JSON.stringify(settings, null, 2)}
319
- `);
320
- }
321
- return { ok: true, target: "antigravity", path: file, changed, configured: true, rules: [...ANTIGRAVITY_CADRE_ALLOW_RULES] };
322
- }
323
- function checkAntigravityApprovals() {
324
- const file = approvalConfigPath("antigravity");
325
- const parsed = readJsonSettings(file, "antigravity", ANTIGRAVITY_CADRE_ALLOW_RULES);
326
- if (!parsed.ok) return parsed.result;
327
- const permissions = isRecord(parsed.settings.permissions) ? parsed.settings.permissions : {};
328
- const allow = Array.isArray(permissions.allow) ? permissions.allow.filter((item) => typeof item === "string") : [];
329
- const missing = ANTIGRAVITY_CADRE_ALLOW_RULES.filter((rule) => !allow.includes(rule));
330
- const result = {
331
- ok: missing.length === 0,
332
- target: "antigravity",
333
- path: file,
334
- changed: false,
335
- configured: missing.length === 0,
336
- rules: missing.length === 0 ? [...ANTIGRAVITY_CADRE_ALLOW_RULES] : missing
337
- };
338
- if (missing.length > 0) result.error = `missing Antigravity Cadre tool allow rules: ${missing.join(", ")}`;
339
- return result;
340
- }
341
- function copilotPromptResult() {
342
- return {
343
- ok: true,
344
- target: "copilot",
345
- path: approvalConfigPath("copilot"),
346
- changed: false,
347
- configured: false,
348
- rules: []
349
- };
350
- }
351
- function readClaudeSettings(file) {
352
- return readJsonSettings(file, "claude", CLAUDE_CADRE_ALLOW_RULES);
353
- }
354
- function readJsonSettings(file, target, rules) {
355
- if (!import_node_fs.default.existsSync(file)) return { ok: true, settings: {} };
356
- try {
357
- const parsed = JSON.parse(import_node_fs.default.readFileSync(file, "utf8"));
358
- if (isRecord(parsed)) return { ok: true, settings: parsed };
359
- return {
360
- ok: false,
361
- result: { ok: false, target, path: file, changed: false, configured: false, rules: [...rules], error: `${file} must contain a JSON object` }
362
- };
363
- } catch (error) {
364
- return {
365
- ok: false,
366
- result: {
367
- ok: false,
368
- target,
369
- path: file,
370
- changed: false,
371
- configured: false,
372
- rules: [...rules],
373
- error: error instanceof Error ? error.message : String(error)
374
- }
375
- };
376
- }
377
- }
378
- function isRecord(value) {
379
- return typeof value === "object" && value !== null && !Array.isArray(value);
380
- }
381
-
382
- // src/cli/install-checks.ts
383
- var import_node_fs2 = __toESM(require("node:fs"));
384
- var import_node_path3 = __toESM(require("node:path"));
385
- var import_node_child_process2 = require("node:child_process");
386
-
387
- // src/guards.ts
388
- function isRecord2(value) {
389
- return typeof value === "object" && value !== null && !Array.isArray(value);
390
- }
391
- function asJsonObject(value) {
392
- return isRecord2(value) ? value : {};
393
- }
394
- function asOptionalString(value) {
395
- return typeof value === "string" ? value : void 0;
396
- }
397
-
398
- // src/mcp/domain/tool-catalog.ts
399
- var SUPPORTED_PROTOCOL_VERSIONS = ["2025-11-25", "2025-06-18"];
400
- var PROTOCOL_VERSION = SUPPORTED_PROTOCOL_VERSIONS[0];
401
- var SERVER_INSTRUCTIONS = [
402
- "Cadre is a packet-led runtime. Call cadre_workflow first for workflows, cadre_action for a packet named by a workflow response, and cadre_read only for a relevant resource URI.",
403
- "Pass a root candidate to project-scoped calls. Cadre resolves it internally; setup accepts an uninitialized directory.",
404
- "Cadre owns control-plane, provider, worker, approval, merge, and generated projection state."
405
- ].join(" ");
406
-
407
- // src/cli/install-checks.ts
408
- function runCommand(plan) {
409
- const result = (0, import_node_child_process2.spawnSync)(plan.command, plan.args, { encoding: "utf8" });
410
- return { ok: result.status === 0, status: result.status, stderr: result.stderr || "" };
411
- }
412
- function pingMcp(runtime) {
413
- if (!import_node_fs2.default.existsSync(runtime.mcpServer)) return { ok: false, reason: `missing MCP server: ${runtime.mcpServer}` };
414
- const messages = [
415
- {
416
- jsonrpc: "2.0",
417
- id: 1,
418
- method: "initialize",
419
- params: {
420
- protocolVersion: PROTOCOL_VERSION,
421
- capabilities: {},
422
- clientInfo: { name: "cadre-installer", version: "1" }
423
- }
424
- },
425
- { jsonrpc: "2.0", method: "notifications/initialized" },
426
- {
427
- jsonrpc: "2.0",
428
- id: 2,
429
- method: "tools/call",
430
- params: { name: "cadre_action", arguments: { action: "project.ping" } }
431
- }
432
- ];
433
- const result = (0, import_node_child_process2.spawnSync)(runtime.nodePath, [runtime.mcpServer], {
434
- cwd: runtime.runtimeRoot,
435
- input: `${messages.map((message) => JSON.stringify(message)).join("\n")}
436
- `,
437
- encoding: "utf8",
438
- timeout: 3e3
439
- });
440
- if (result.status !== 0 && !result.stdout.trim()) return { ok: false, reason: result.stderr || `MCP exited with ${result.status}` };
441
- try {
442
- const responses = result.stdout.split(/\r?\n/).filter((entry) => entry.trim()).map((entry) => asJsonObject(JSON.parse(entry)));
443
- const initialize = responses.find((response) => response.id === 1);
444
- const ping = responses.find((response) => response.id === 2);
445
- if (!initialize) return { ok: false, reason: "MCP returned no initialize response" };
446
- const initializeError = asJsonObject(initialize.error);
447
- if (Object.keys(initializeError).length > 0) return { ok: false, reason: asOptionalString(initializeError.message) || "MCP initialize returned an error" };
448
- const initializeResult = asJsonObject(initialize.result);
449
- if (initializeResult.protocolVersion !== PROTOCOL_VERSION) {
450
- return { ok: false, reason: `MCP negotiated ${initializeResult.protocolVersion || "no protocol version"}; expected ${PROTOCOL_VERSION}` };
451
- }
452
- if (!ping) return { ok: false, reason: "MCP returned no ping response after initialization" };
453
- const pingError = asJsonObject(ping.error);
454
- if (Object.keys(pingError).length > 0) return { ok: false, reason: asOptionalString(pingError.message) || "MCP ping returned an error" };
455
- const pingResult = asJsonObject(ping.result);
456
- const content = Array.isArray(pingResult.content) ? pingResult.content : [];
457
- const text = asOptionalString(asJsonObject(content[0]).text);
458
- const body = text ? JSON.parse(text) : null;
459
- return body?.data?.ok === true ? { ok: true } : { ok: false, reason: "MCP ping did not return ok:true" };
460
- } catch (error) {
461
- return { ok: false, reason: error instanceof Error ? error.message : String(error) };
462
- }
463
- }
464
- function forbiddenThinPayload(root) {
465
- return ["assets", "agents", "scripts", "references", "templates"].filter((name) => import_node_fs2.default.existsSync(import_node_path3.default.join(root, name))).map((name) => `${root}/${name}`);
466
- }
467
- function pluginConfigFiles(target, pluginRoot) {
468
- if (target === "codex") {
469
- return { manifest: import_node_path3.default.join(pluginRoot, ".codex-plugin", "plugin.json"), mcp: import_node_path3.default.join(pluginRoot, ".mcp.json") };
470
- }
471
- if (target === "claude") {
472
- return { manifest: import_node_path3.default.join(pluginRoot, ".claude-plugin", "plugin.json"), mcp: import_node_path3.default.join(pluginRoot, "mcp-config.json") };
473
- }
474
- if (target === "copilot") {
475
- return { manifest: import_node_path3.default.join(pluginRoot, "plugin.json"), mcp: import_node_path3.default.join(pluginRoot, ".mcp.json") };
476
- }
477
- return { manifest: import_node_path3.default.join(pluginRoot, "plugin.json"), mcp: import_node_path3.default.join(pluginRoot, "mcp_config.json") };
478
- }
479
- function checkMcpConfig(target, file, runtime) {
480
- const errors = [];
481
- const config = JSON.parse(import_node_fs2.default.readFileSync(file, "utf8"));
482
- const server = config.mcpServers?.cadre;
483
- if (server?.command !== runtime.nodePath) errors.push(`${file} does not point at the current Node runtime`);
484
- if (server?.args?.[0] !== runtime.mcpServer) errors.push(`${file} does not point at ${runtime.mcpServer}`);
485
- if (server?.cwd !== runtime.runtimeRoot) errors.push(`${file} has wrong cwd`);
486
- if (target === "copilot") {
487
- if (server?.type !== "local") errors.push(`${file} must declare Copilot local MCP type`);
488
- if (!server?.tools?.includes("*")) errors.push(`${file} must allow Copilot MCP tools`);
489
- }
490
- return errors;
491
- }
492
- function checkCommandSkills(platform, pluginRoot, commandSkills) {
493
- const errors = [];
494
- if (Object.keys(commandSkills).length === 0) return [`Cadre ${platform} workflow commands are missing`];
495
- for (const [command, files] of Object.entries(commandSkills)) {
496
- const commandRoot = import_node_path3.default.join(pluginRoot, "skills", command);
497
- if (import_node_fs2.default.existsSync(commandRoot) && !import_node_fs2.default.lstatSync(commandRoot).isDirectory()) {
498
- errors.push(`invalid Cadre command skill directory ${commandRoot}`);
499
- continue;
500
- }
501
- const expectedFiles = new Set(Object.keys(files).map((relative) => relative.replace(/\\/g, "/")));
502
- const expectedDirectories = /* @__PURE__ */ new Set();
503
- for (const relative of expectedFiles) {
504
- const parts = relative.split("/");
505
- for (let index = 1; index < parts.length; index += 1) {
506
- expectedDirectories.add(parts.slice(0, index).join("/"));
507
- }
508
- }
509
- for (const [relative, expected] of Object.entries(files)) {
510
- const file = import_node_path3.default.join(pluginRoot, "skills", command, ...relative.replace(/\\/g, "/").split("/"));
511
- if (!import_node_fs2.default.existsSync(file)) {
512
- errors.push(`missing ${file}`);
513
- continue;
514
- }
515
- if (!import_node_fs2.default.lstatSync(file).isFile()) {
516
- errors.push(`invalid Cadre command skill file ${file}`);
517
- continue;
518
- }
519
- const actual = import_node_fs2.default.readFileSync(file, "utf8");
520
- const normalizedExpected = expected.endsWith("\n") ? expected : `${expected}
521
- `;
522
- if (actual !== normalizedExpected) errors.push(`stale Cadre command skill ${file}`);
523
- }
524
- if (import_node_fs2.default.existsSync(commandRoot)) {
525
- const visit = (directory, relativeRoot = "") => {
526
- for (const entry of import_node_fs2.default.readdirSync(directory, { withFileTypes: true })) {
527
- const relative = import_node_path3.default.posix.join(relativeRoot, entry.name);
528
- if (entry.isDirectory()) {
529
- if (expectedDirectories.has(relative)) visit(import_node_path3.default.join(directory, entry.name), relative);
530
- else errors.push(`unexpected Cadre command skill directory ${import_node_path3.default.join(commandRoot, ...relative.split("/"))}`);
531
- } else if (!expectedFiles.has(relative)) {
532
- errors.push(`unexpected Cadre command skill file ${import_node_path3.default.join(commandRoot, ...relative.split("/"))}`);
533
- }
534
- }
535
- };
536
- visit(commandRoot);
537
- }
538
- }
539
- const skillsRoot = import_node_path3.default.join(pluginRoot, "skills");
540
- const expectedCommands = new Set(Object.keys(commandSkills));
541
- if (import_node_fs2.default.existsSync(skillsRoot)) {
542
- for (const entry of import_node_fs2.default.readdirSync(skillsRoot, { withFileTypes: true })) {
543
- if (!entry.isDirectory() || !expectedCommands.has(entry.name)) {
544
- errors.push(`unexpected Cadre command skill ${import_node_path3.default.join(skillsRoot, entry.name)}`);
545
- }
546
- }
547
- }
548
- return errors;
549
- }
550
- function checkTarget(target, paths, runtime, commandSkillSets) {
551
- const errors = [];
552
- for (const skillRoot of paths.skillRoots) {
553
- const skill = import_node_path3.default.join(skillRoot, "SKILL.md");
554
- if (!import_node_fs2.default.existsSync(skill)) errors.push(`missing ${skill}`);
555
- }
556
- for (const pluginRoot of paths.pluginRoots) {
557
- if (target !== "codex" && target !== "claude") {
558
- const skill = import_node_path3.default.join(pluginRoot, "skills", "cadre", "SKILL.md");
559
- if (!import_node_fs2.default.existsSync(skill)) errors.push(`missing ${skill}`);
560
- }
561
- const files = pluginConfigFiles(target, pluginRoot);
562
- if (!import_node_fs2.default.existsSync(files.manifest)) errors.push(`missing ${files.manifest}`);
563
- if (!import_node_fs2.default.existsSync(files.mcp)) errors.push(`missing ${files.mcp}`);
564
- errors.push(...forbiddenThinPayload(pluginRoot).map((entry) => `thin plugin contains forbidden payload ${entry}`));
565
- if (import_node_fs2.default.existsSync(files.mcp)) errors.push(...checkMcpConfig(target, files.mcp, runtime));
566
- if (target === "codex" || target === "claude") {
567
- errors.push(...checkCommandSkills(target, pluginRoot, commandSkillSets[target]));
568
- }
569
- }
570
- if (paths.marketplaceFile && !import_node_fs2.default.existsSync(paths.marketplaceFile)) errors.push(`missing ${paths.marketplaceFile}`);
571
- return errors;
572
- }
573
- function printPlan(target, paths, commands) {
574
- if (paths.pluginRoots.length > 0) process.stdout.write(`Cadre ${target} plugin: ${paths.pluginRoots.join(", ")}
575
- `);
576
- if (paths.skillRoots.length > 0) process.stdout.write(`Cadre ${target} skill: ${paths.skillRoots.join(", ")}
577
- `);
578
- if (paths.marketplaceRoot) process.stdout.write(`Cadre ${target} marketplace: ${paths.marketplaceRoot}
579
- `);
580
- for (const command of commands) process.stdout.write(`Would run: ${command.command} ${command.args.join(" ")}
581
- `);
582
- }
583
-
584
- // src/cli/install-writers.ts
585
- var import_node_fs3 = __toESM(require("node:fs"));
586
- var import_node_path4 = __toESM(require("node:path"));
587
- var MARKETPLACE_PLUGIN_SOURCE = "./plugins/cadre";
588
- function readPackageMetadata(runtimeRoot) {
589
- try {
590
- const json = JSON.parse(import_node_fs3.default.readFileSync(import_node_path4.default.join(runtimeRoot, "package.json"), "utf8"));
591
- return {
592
- version: typeof json.version === "string" ? json.version : "0.0.0",
593
- description: typeof json.description === "string" ? json.description : "MCP-first Cadre workflows.",
594
- homepage: typeof json.homepage === "string" ? json.homepage : "https://cadre-docs.pages.dev/",
595
- repository: typeof json.repository === "string" ? json.repository : "https://github.com/vishal-kr-barnwal/cadre",
596
- license: typeof json.license === "string" ? json.license : "Apache-2.0"
597
- };
598
- } catch {
599
- return {
600
- version: "0.0.0",
601
- description: "MCP-first Cadre workflows.",
602
- homepage: "https://cadre-docs.pages.dev/",
603
- repository: "https://github.com/vishal-kr-barnwal/cadre",
604
- license: "Apache-2.0"
605
- };
606
- }
607
- }
608
- function baseManifest(runtime) {
609
- const metadata = readPackageMetadata(runtime.runtimeRoot);
610
- return {
611
- name: PACKAGE_PLUGIN_NAME,
612
- version: metadata.version,
613
- description: metadata.description,
614
- author: { name: "Vishal Kumar", url: "https://github.com/vishal-kr-barnwal" },
615
- homepage: metadata.homepage,
616
- repository: metadata.repository,
617
- license: metadata.license,
618
- keywords: ["cadre", "context-driven-development", "skills", "mcp"],
619
- skills: "./skills/"
620
- };
621
- }
622
- function pluginManifest(target, runtime) {
623
- const base = baseManifest(runtime);
624
- if (target === "claude") return { ...base, displayName: PACKAGE_DISPLAY_NAME, mcpServers: "./mcp-config.json" };
625
- if (target === "antigravity") {
626
- return {
627
- $schema: "https://antigravity.google/schemas/v1/plugin.json",
628
- name: PACKAGE_PLUGIN_NAME,
629
- description: base.description,
630
- version: base.version
631
- };
632
- }
633
- const mcpServers = "./.mcp.json";
634
- const codexInterface = {
635
- displayName: PACKAGE_DISPLAY_NAME,
636
- shortDescription: "MCP-first planning, tracks, reviews, and packet tools.",
637
- longDescription: "Cadre packages context-driven development workflows through one global MCP runtime.",
638
- developerName: "Vishal Kumar",
639
- category: "Productivity",
640
- capabilities: ["Read", "Write", "Interactive"],
641
- defaultPrompt: ["Set up this repo with Cadre.", "Show Cadre team status.", "Review the current Cadre track."],
642
- brandColor: "#10A37F"
643
- };
644
- return target === "copilot" ? { ...base, mcpServers } : { ...base, mcpServers, interface: codexInterface };
645
- }
646
- function mcpConfig(target, runtime) {
647
- const server = {
648
- command: runtime.nodePath,
649
- args: [runtime.mcpServer],
650
- cwd: runtime.runtimeRoot
651
- };
652
- if (target === "copilot") {
653
- server.type = "local";
654
- server.tools = ["*"];
655
- }
656
- return { mcpServers: { cadre: server } };
657
- }
658
- function marketplace(target, runtime) {
659
- const metadata = readPackageMetadata(runtime.runtimeRoot);
660
- if (target === "codex") {
661
- return {
662
- name: PACKAGE_PLUGIN_NAME,
663
- interface: { displayName: PACKAGE_DISPLAY_NAME },
664
- plugins: [{
665
- name: PACKAGE_PLUGIN_NAME,
666
- source: { source: "local", path: MARKETPLACE_PLUGIN_SOURCE },
667
- policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
668
- category: "Productivity"
669
- }]
670
- };
671
- }
672
- return {
673
- name: PACKAGE_PLUGIN_NAME,
674
- owner: { name: "Vishal Kumar" },
675
- description: "Cadre MCP-first workflows for Claude Code.",
676
- plugins: [{
677
- name: PACKAGE_PLUGIN_NAME,
678
- source: MARKETPLACE_PLUGIN_SOURCE,
679
- description: metadata.description,
680
- version: metadata.version,
681
- author: { name: "Vishal Kumar" },
682
- category: "productivity",
683
- tags: ["cadre", "skills", "mcp", "context-driven-development"]
684
- }]
685
- };
686
- }
687
- function writeJson(file, value) {
688
- import_node_fs3.default.mkdirSync(import_node_path4.default.dirname(file), { recursive: true });
689
- import_node_fs3.default.writeFileSync(file, `${JSON.stringify(value, null, 2)}
690
- `);
691
- }
692
- function writeText(file, text) {
693
- import_node_fs3.default.mkdirSync(import_node_path4.default.dirname(file), { recursive: true });
694
- import_node_fs3.default.writeFileSync(file, text.endsWith("\n") ? text : `${text}
695
- `);
696
- }
697
- function writeCommandSkills(pluginRoot, commandSkills) {
698
- for (const [command, files] of Object.entries(commandSkills)) {
699
- if (command === "cadre" || !/^[a-z][a-z0-9-]*$/.test(command)) {
700
- throw new Error(`Invalid Cadre command skill: ${command}`);
701
- }
702
- for (const [relative, content] of Object.entries(files)) {
703
- const normalized = relative.replace(/\\/g, "/");
704
- if (!normalized || normalized.startsWith("/") || normalized.split("/").some((part) => !part || part === "." || part === "..")) {
705
- throw new Error(`Invalid Cadre command skill file: ${command}/${relative}`);
706
- }
707
- writeText(import_node_path4.default.join(pluginRoot, "skills", command, ...normalized.split("/")), content);
708
- }
709
- }
710
- }
711
- function writePluginRoot(target, pluginRoot, runtime, skillShim, commandSkillSets) {
712
- const commandSkills = target === "codex" || target === "claude" ? commandSkillSets[target] : null;
713
- if (commandSkills && Object.keys(commandSkills).length === 0) {
714
- throw new Error(`Cadre ${target} workflow commands are missing`);
715
- }
716
- import_node_fs3.default.rmSync(pluginRoot, { recursive: true, force: true });
717
- if (commandSkills) {
718
- writeCommandSkills(pluginRoot, commandSkills);
719
- } else {
720
- writeText(import_node_path4.default.join(pluginRoot, "skills", "cadre", "SKILL.md"), skillShim);
721
- }
722
- if (target === "codex") {
723
- writeJson(import_node_path4.default.join(pluginRoot, ".codex-plugin", "plugin.json"), pluginManifest(target, runtime));
724
- writeJson(import_node_path4.default.join(pluginRoot, ".mcp.json"), mcpConfig(target, runtime));
725
- } else if (target === "claude") {
726
- writeJson(import_node_path4.default.join(pluginRoot, ".claude-plugin", "plugin.json"), pluginManifest(target, runtime));
727
- writeJson(import_node_path4.default.join(pluginRoot, "mcp-config.json"), mcpConfig(target, runtime));
728
- } else if (target === "copilot") {
729
- writeJson(import_node_path4.default.join(pluginRoot, "plugin.json"), pluginManifest(target, runtime));
730
- writeJson(import_node_path4.default.join(pluginRoot, ".mcp.json"), mcpConfig(target, runtime));
731
- } else {
732
- writeJson(import_node_path4.default.join(pluginRoot, "plugin.json"), pluginManifest(target, runtime));
733
- writeJson(import_node_path4.default.join(pluginRoot, "mcp_config.json"), mcpConfig(target, runtime));
734
- }
735
- }
736
- function writeTarget(target, paths, runtime, skillShim, commandSkillSets) {
737
- for (const pluginRoot of paths.pluginRoots) writePluginRoot(target, pluginRoot, runtime, skillShim, commandSkillSets);
738
- for (const skillRoot of paths.skillRoots) {
739
- import_node_fs3.default.rmSync(skillRoot, { recursive: true, force: true });
740
- writeText(import_node_path4.default.join(skillRoot, "SKILL.md"), skillShim);
741
- }
742
- if (paths.marketplaceFile && (target === "codex" || target === "claude")) {
743
- writeJson(paths.marketplaceFile, marketplace(target, runtime));
744
- }
745
- }
746
- function removeTarget(paths) {
747
- const roots = /* @__PURE__ */ new Set();
748
- if (paths.marketplaceRoot) roots.add(paths.marketplaceRoot);
749
- for (const pluginRoot of paths.pluginRoots) roots.add(pluginRoot);
750
- for (const skillRoot of paths.skillRoots) roots.add(skillRoot);
751
- const removed = [];
752
- for (const root of roots) {
753
- if (!import_node_fs3.default.existsSync(root)) continue;
754
- import_node_fs3.default.rmSync(root, { recursive: true, force: true });
755
- removed.push(root);
756
- }
757
- return removed;
758
- }
759
-
760
- // src/cli/install.ts
761
- function usage() {
762
- return [
763
- "Cadre CLI",
764
- "",
765
- "Usage:",
766
- " cadre install [--target codex|claude|copilot|antigravity|all] [--scope user|project|local] [--dry-run] [--check] [--force] [--yes]",
767
- " cadre uninstall [--target codex|claude|copilot|antigravity|all] [--scope user|project|local] [--dry-run] [--yes]",
768
- " cadre doctor",
769
- " cadre help"
770
- ].join("\n");
771
- }
772
- function parseTarget(value) {
773
- if (!value) throw new Error("--target requires a value");
774
- if (value === "all") return value;
775
- if (INSTALL_TARGETS.includes(value)) return value;
776
- throw new Error("--target must be codex, claude, copilot, antigravity, or all");
777
- }
778
- function parseScope(value) {
779
- if (value === "user" || value === "project" || value === "local") return value;
780
- throw new Error("--scope must be user, project, or local");
781
- }
782
- function parseInstall(argv) {
783
- const parsed = {
784
- target: "auto",
785
- scope: "user",
786
- dryRun: false,
787
- check: false,
788
- force: false,
789
- yes: false,
790
- cadreHome: process.env.CADRE_HOME || import_node_path5.default.join(import_node_os3.default.homedir(), ".cadre")
791
- };
792
- for (let index = 0; index < argv.length; index += 1) {
793
- const arg = argv[index];
794
- if (arg === "--dry-run") parsed.dryRun = true;
795
- else if (arg === "--check") parsed.check = true;
796
- else if (arg === "--force") parsed.force = true;
797
- else if (arg === "--yes" || arg === "-y") parsed.yes = true;
798
- else if (arg === "--target") {
799
- parsed.target = parseTarget(argv[index + 1]);
800
- index += 1;
801
- } else if (arg === "--scope") {
802
- parsed.scope = parseScope(argv[index + 1]);
803
- index += 1;
804
- } else if (arg === "--home") {
805
- const value = argv[index + 1];
806
- if (!value) throw new Error("--home requires a path");
807
- parsed.cadreHome = import_node_path5.default.resolve(value);
808
- index += 1;
809
- } else {
810
- throw new Error(`Unknown install option: ${arg}`);
811
- }
812
- }
813
- return parsed;
814
- }
815
- function printApprovalResult(target, path6, configured) {
816
- if (configured) {
817
- process.stdout.write(`Cadre ${target} MCP tool approvals are configured in ${path6}
818
- `);
819
- } else {
820
- process.stdout.write(`Cadre ${target} MCP tools may prompt on first use; no approval file was changed.
821
- `);
822
- }
823
- }
824
- function installedNoun(paths) {
825
- return paths.pluginRoots.length > 0 ? "plugin" : "skill";
826
- }
827
- function pathsExist(paths) {
828
- return Boolean(
829
- 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))
830
- );
831
- }
832
- function selectedUninstallTargets(options) {
833
- if (options.target !== "auto" && options.target !== "all") return [options.target];
834
- if (options.target === "all") return [...INSTALL_TARGETS];
835
- return INSTALL_TARGETS.filter(
836
- (target) => commandExists(target === "antigravity" ? "agy" : target) || pathsExist(targetPaths(options.cadreHome, target, options.scope))
837
- );
838
- }
839
- function printUninstallPlan(target, paths, commands) {
840
- if (paths.marketplaceRoot) process.stdout.write(`Would remove: ${paths.marketplaceRoot}
841
- `);
842
- for (const pluginRoot of paths.pluginRoots) process.stdout.write(`Would remove: ${pluginRoot}
843
- `);
844
- for (const skillRoot of paths.skillRoots) process.stdout.write(`Would remove: ${skillRoot}
845
- `);
846
- for (const command of commands) process.stdout.write(`Would run: ${command.command} ${command.args.join(" ")}
847
- `);
848
- if (!pathsExist(paths) && commands.length === 0) process.stdout.write(`No Cadre ${target} files or native uninstall commands found.
849
- `);
850
- }
851
- function missingInstallCommandIsWarning(options, target, optional) {
852
- return optional === true || options.target === "all" && target === "copilot";
853
- }
854
- function runInstall(argv, context) {
855
- const options = parseInstall(argv);
856
- const runtime = runtimePaths();
857
- const targets = selectedTargets(options);
858
- if (targets.length === 0) {
859
- process.stderr.write("No supported client detected. Install Codex, Claude, Copilot, or Antigravity, or pass --target codex|claude|copilot|antigravity.\n");
860
- return 1;
861
- }
862
- const ping = pingMcp(runtime);
863
- if (!ping.ok) {
864
- process.stderr.write(`Cadre MCP check failed: ${ping.reason}
865
- `);
866
- return 1;
867
- }
868
- let ok = true;
869
- for (const target of targets) {
870
- let targetOk = true;
871
- const paths = targetPaths(options.cadreHome, target, options.scope);
872
- const commands = installCommands(target, paths, options.scope);
873
- if (options.dryRun) {
874
- printPlan(target, paths, commands);
875
- process.stdout.write(`Would configure: ${approvalSummary(target)}
876
- `);
877
- continue;
878
- }
879
- if (!options.check) writeTarget(target, paths, runtime, context.skillShim, context.commandSkills);
880
- const errors = checkTarget(target, paths, runtime, context.commandSkills);
881
- if (!options.check) {
882
- const approvals = bootstrapClientApprovals(target);
883
- if (!approvals.ok) errors.push(`${target} approval bootstrap failed: ${approvals.error || approvals.path}`);
884
- }
885
- const approvalCheck = checkClientApprovals(target);
886
- if (!approvalCheck.ok) errors.push(`${target} approval check failed: ${approvalCheck.error || approvalCheck.path}`);
887
- if (errors.length > 0) {
888
- ok = false;
889
- targetOk = false;
890
- for (const error of errors) process.stderr.write(`${error}
891
- `);
892
- continue;
893
- }
894
- if (options.check) {
895
- process.stdout.write(`Cadre ${target} ${installedNoun(paths)} is installed and points at ${runtime.mcpServer}
896
- `);
897
- printApprovalResult(target, approvalCheck.path, approvalCheck.configured);
898
- continue;
899
- }
900
- for (const command of commands) {
901
- if (!commandExists(command.command)) {
902
- const message = `${command.command} command not found; plugin files were written but native registration was skipped.
903
- `;
904
- if (missingInstallCommandIsWarning(options, target, command.optional)) process.stderr.write(message);
905
- else {
906
- targetOk = false;
907
- ok = false;
908
- process.stderr.write(message);
909
- }
910
- continue;
911
- }
912
- const result = runCommand(command);
913
- if (!result.ok) {
914
- targetOk = false;
915
- ok = false;
916
- process.stderr.write(`${command.command} ${command.args.join(" ")} failed: ${result.stderr}
917
- `);
918
- }
919
- }
920
- if (targetOk) {
921
- process.stdout.write(`Installed Cadre ${target} ${installedNoun(paths)} through ${paths.primaryRoot}
922
- `);
923
- printApprovalResult(target, approvalCheck.path, approvalCheck.configured);
924
- }
925
- }
926
- return ok ? 0 : 1;
927
- }
928
- function runUninstall(argv) {
929
- const options = parseInstall(argv);
930
- const targets = selectedUninstallTargets(options);
931
- if (targets.length === 0) {
932
- process.stderr.write("No Cadre client install found. Pass --target codex|claude|copilot|antigravity to remove a specific generated target.\n");
933
- return 1;
934
- }
935
- for (const target of targets) {
936
- const paths = targetPaths(options.cadreHome, target, options.scope);
937
- const commands = uninstallCommands(target, paths, options.scope);
938
- if (options.dryRun) {
939
- printUninstallPlan(target, paths, commands);
940
- continue;
941
- }
942
- for (const command of commands) {
943
- if (!commandExists(command.command)) {
944
- process.stderr.write(`${command.command} command not found; removing generated Cadre ${target} files only.
945
- `);
946
- continue;
947
- }
948
- const result = runCommand(command);
949
- if (!result.ok) {
950
- process.stderr.write(`${command.command} ${command.args.join(" ")} failed; continuing local cleanup: ${result.stderr}
951
- `);
952
- }
953
- }
954
- const removed = removeTarget(paths);
955
- if (removed.length > 0) {
956
- process.stdout.write(`Uninstalled Cadre ${target} ${installedNoun(paths)} and removed ${removed.join(", ")}
957
- `);
958
- } else {
959
- process.stdout.write(`No generated Cadre ${target} files found to remove.
960
- `);
961
- }
962
- }
963
- return 0;
964
- }
965
- function runDoctor() {
966
- const runtime = runtimePaths();
967
- const ping = pingMcp(runtime);
968
- const checks = [
969
- `package root: ${runtime.runtimeRoot}`,
970
- `node: ${runtime.nodePath}`,
971
- `cadre-mcp: ${runtime.mcpServer}`,
972
- `mcp ping: ${ping.ok ? "ok" : `failed (${ping.reason})`}`
973
- ];
974
- process.stdout.write(`${checks.join("\n")}
975
- `);
976
- return ping.ok ? 0 : 1;
977
- }
978
- async function runCli(argv, context) {
979
- const command = argv[0] || "help";
980
- let code = 0;
981
- if (command === "install") code = runInstall(argv.slice(1), context);
982
- else if (command === "uninstall" || command === "remove") code = runUninstall(argv.slice(1));
983
- else if (command === "doctor") code = runDoctor();
984
- else if (command === "help" || command === "--help" || command === "-h") process.stdout.write(`${usage()}
985
- `);
986
- else {
987
- process.stderr.write(`${usage()}
988
- `);
989
- code = 1;
990
- }
991
- if (code !== 0) process.exit(code);
992
- }
993
-
994
- // src/cli/workflow-command-skills.ts
995
- var workflowPattern = /^[a-z][a-z0-9-]*$/;
996
- var claudeFrontmatterEnd = "\n---\n";
997
- var WORKFLOW_COMMAND_PLATFORMS = ["codex", "claude"];
998
- function workflowDisplayName(workflow) {
999
- if (workflow === "newtrack") return "New Track";
1000
- return workflow.split("-").map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join(" ");
1001
- }
1002
- function commandAgentManifest(workflow) {
1003
- const displayName = workflowDisplayName(workflow);
1004
- return [
1005
- "interface:",
1006
- ` display_name: "Cadre ${displayName}"`,
1007
- ` short_description: "Start or continue the Cadre ${displayName} workflow"`,
1008
- ` default_prompt: "Start or continue the Cadre ${workflow} workflow for this project."`,
1009
- "policy:",
1010
- " allow_implicit_invocation: false",
1011
- ""
1012
- ].join("\n");
1013
- }
1014
- function claudeCommandSkill(content) {
1015
- if (!content.startsWith("---\n")) {
1016
- throw new Error("Cadre workflow command template is missing YAML frontmatter");
1017
- }
1018
- const frontmatterEnd = content.indexOf(claudeFrontmatterEnd, 4);
1019
- if (frontmatterEnd < 0) {
1020
- throw new Error("Cadre workflow command template has unterminated YAML frontmatter");
1021
- }
1022
- const frontmatter = content.slice(4, frontmatterEnd);
1023
- if (/^disable-model-invocation:/m.test(frontmatter)) {
1024
- throw new Error("Cadre workflow command template must keep Claude invocation policy platform-specific");
1025
- }
1026
- return `${content.slice(0, frontmatterEnd)}
1027
- disable-model-invocation: true${content.slice(frontmatterEnd)}`;
1028
- }
1029
- function commandFiles(platform, workflow, content) {
1030
- if (platform === "claude") {
1031
- return { "SKILL.md": claudeCommandSkill(content) };
1032
- }
1033
- return {
1034
- "SKILL.md": content,
1035
- "agents/openai.yaml": commandAgentManifest(workflow)
1036
- };
1037
- }
1038
- function renderWorkflowCommandSkills(template, workflows, options = {}) {
1039
- const platform = options.platform ?? "codex";
1040
- if (!WORKFLOW_COMMAND_PLATFORMS.includes(platform)) {
1041
- throw new Error(`Unsupported Cadre workflow command platform: ${String(platform)}`);
1042
- }
1043
- if (!template.includes("{{command}}") || !template.includes("{{workflow}}")) {
1044
- throw new Error("Cadre workflow command template is missing required placeholders");
1045
- }
1046
- const unique = /* @__PURE__ */ new Set();
1047
- const commandSkills = {};
1048
- for (const workflow of workflows) {
1049
- if (!workflowPattern.test(workflow) || workflow === "cadre" || unique.has(workflow)) {
1050
- throw new Error(`Invalid Cadre workflow command id: ${workflow}`);
1051
- }
1052
- unique.add(workflow);
1053
- const content = template.replaceAll("{{command}}", workflow).replaceAll("{{workflow}}", workflow);
1054
- if (content.includes("{{")) {
1055
- throw new Error(`Unresolved workflow command placeholder: ${workflow}`);
1056
- }
1057
- commandSkills[workflow] = commandFiles(platform, workflow, content);
1058
- }
1059
- return commandSkills;
1060
- }
1061
-
1062
- // src/cli.ts
1063
- var commandSkillTemplate = typeof __CADRE_COMMAND_SKILL_TEMPLATE__ === "string" ? __CADRE_COMMAND_SKILL_TEMPLATE__ : "";
1064
- var workflowCommands = typeof __CADRE_WORKFLOW_COMMANDS__ !== "undefined" && Array.isArray(__CADRE_WORKFLOW_COMMANDS__) ? __CADRE_WORKFLOW_COMMANDS__ : [];
1065
- runCli(process.argv.slice(2), {
1066
- skillShim: typeof __CADRE_SKILL_SHIM__ === "string" ? __CADRE_SKILL_SHIM__ : "",
1067
- commandSkills: {
1068
- codex: renderWorkflowCommandSkills(commandSkillTemplate, workflowCommands, { platform: "codex" }),
1069
- claude: renderWorkflowCommandSkills(commandSkillTemplate, workflowCommands, { platform: "claude" })
1070
- }
1071
- }).catch((error) => {
1072
- const message = error instanceof Error ? error.message : String(error);
1073
- process.stderr.write(`${message}
1074
- `);
1075
- process.exit(1);
1076
- });