cadre-ai 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cadre-ai",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "MCP-first Cadre workflows for context-driven development.",
5
5
  "author": {
6
6
  "name": "Vishal Kumar",
@@ -27,10 +27,193 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
 
29
29
  // src/cli/install.ts
30
+ var import_node_fs2 = __toESM(require("node:fs"));
31
+ var import_node_os2 = __toESM(require("node:os"));
32
+ var import_node_path2 = __toESM(require("node:path"));
33
+ var import_node_child_process = require("node:child_process");
34
+
35
+ // src/cli/client-approvals.ts
30
36
  var import_node_fs = __toESM(require("node:fs"));
31
37
  var import_node_os = __toESM(require("node:os"));
32
38
  var import_node_path = __toESM(require("node:path"));
33
- var import_node_child_process = require("node:child_process");
39
+ var CADRE_MCP_TOOLS = [
40
+ "cadre_resource",
41
+ "cadre_workflow",
42
+ "cadre_project",
43
+ "cadre_status",
44
+ "cadre_track",
45
+ "cadre_parallel",
46
+ "cadre_mutate",
47
+ "cadre_complete_task",
48
+ "cadre_job",
49
+ "cadre_review",
50
+ "cadre_intel",
51
+ "cadre_artifact"
52
+ ];
53
+ var CLAUDE_CADRE_ALLOW_RULES = [
54
+ "mcp__plugin_cadre_cadre__*",
55
+ "mcp__cadre__*"
56
+ ];
57
+ function approvalConfigPath(target) {
58
+ if (target === "codex") {
59
+ return import_node_path.default.join(process.env.CODEX_HOME || import_node_path.default.join(import_node_os.default.homedir(), ".codex"), "config.toml");
60
+ }
61
+ return import_node_path.default.join(process.env.CLAUDE_HOME || process.env.CLAUDE_CONFIG_DIR || import_node_path.default.join(import_node_os.default.homedir(), ".claude"), "settings.json");
62
+ }
63
+ function bootstrapClientApprovals(target) {
64
+ return target === "codex" ? bootstrapCodexApprovals() : bootstrapClaudeApprovals();
65
+ }
66
+ function checkClientApprovals(target) {
67
+ return target === "codex" ? checkCodexApprovals() : checkClaudeApprovals();
68
+ }
69
+ function approvalSummary(target) {
70
+ const file = approvalConfigPath(target);
71
+ if (target === "codex") return `Cadre codex MCP tool approvals: ${file}`;
72
+ return `Cadre claude MCP tool approvals: ${file}`;
73
+ }
74
+ function codexToolSection(tool) {
75
+ return `[plugins."cadre@cadre".mcp_servers.cadre.tools.${tool}]`;
76
+ }
77
+ function codexApprovalSnippet(tool) {
78
+ return `${codexToolSection(tool)}
79
+ approval_mode = "approve"
80
+ `;
81
+ }
82
+ function bootstrapCodexApprovals() {
83
+ const file = approvalConfigPath("codex");
84
+ let text = "";
85
+ if (import_node_fs.default.existsSync(file)) text = import_node_fs.default.readFileSync(file, "utf8");
86
+ const before = text;
87
+ for (const tool of CADRE_MCP_TOOLS) text = upsertCodexApproval(text, tool);
88
+ if (text !== before) {
89
+ import_node_fs.default.mkdirSync(import_node_path.default.dirname(file), { recursive: true });
90
+ import_node_fs.default.writeFileSync(file, text);
91
+ }
92
+ return { ok: true, target: "codex", path: file, changed: text !== before, configured: true, rules: [...CADRE_MCP_TOOLS] };
93
+ }
94
+ function checkCodexApprovals() {
95
+ const file = approvalConfigPath("codex");
96
+ if (!import_node_fs.default.existsSync(file)) {
97
+ return { ok: false, target: "codex", path: file, changed: false, configured: false, rules: [...CADRE_MCP_TOOLS], error: `missing ${file}` };
98
+ }
99
+ const text = import_node_fs.default.readFileSync(file, "utf8");
100
+ const missing = CADRE_MCP_TOOLS.filter((tool) => !codexToolApproved(text, tool));
101
+ const result = {
102
+ ok: missing.length === 0,
103
+ target: "codex",
104
+ path: file,
105
+ changed: false,
106
+ configured: missing.length === 0,
107
+ rules: missing.length === 0 ? [...CADRE_MCP_TOOLS] : missing
108
+ };
109
+ if (missing.length > 0) result.error = `missing Codex Cadre tool approvals: ${missing.join(", ")}`;
110
+ return result;
111
+ }
112
+ function upsertCodexApproval(text, tool) {
113
+ let next = text.endsWith("\n") || text.length === 0 ? text : `${text}
114
+ `;
115
+ const header = codexToolSection(tool);
116
+ const lines = next.split("\n");
117
+ const start = lines.findIndex((line) => line.trim() === header);
118
+ if (start === -1) {
119
+ const spacer = next.trim().length > 0 && !next.endsWith("\n\n") ? "\n" : "";
120
+ return `${next}${spacer}${codexApprovalSnippet(tool)}`;
121
+ }
122
+ let end = lines.length;
123
+ for (let index = start + 1; index < lines.length; index += 1) {
124
+ if (lines[index]?.trim().startsWith("[")) {
125
+ end = index;
126
+ break;
127
+ }
128
+ }
129
+ for (let index = start + 1; index < end; index += 1) {
130
+ if (/^\s*approval_mode\s*=/.test(lines[index] || "")) {
131
+ lines[index] = 'approval_mode = "approve"';
132
+ return lines.join("\n");
133
+ }
134
+ }
135
+ lines.splice(start + 1, 0, 'approval_mode = "approve"');
136
+ return lines.join("\n");
137
+ }
138
+ function codexToolApproved(text, tool) {
139
+ const lines = text.split(/\r?\n/);
140
+ const header = codexToolSection(tool);
141
+ const start = lines.findIndex((line) => line.trim() === header);
142
+ if (start === -1) return false;
143
+ for (let index = start + 1; index < lines.length; index += 1) {
144
+ const line = lines[index]?.trim() || "";
145
+ if (line.startsWith("[")) return false;
146
+ if (line === 'approval_mode = "approve"' || line === "approval_mode = 'approve'") return true;
147
+ }
148
+ return false;
149
+ }
150
+ function bootstrapClaudeApprovals() {
151
+ const file = approvalConfigPath("claude");
152
+ const parsed = readClaudeSettings(file);
153
+ if (!parsed.ok) return parsed.result;
154
+ const settings = parsed.settings;
155
+ const permissions = isRecord(settings.permissions) ? settings.permissions : {};
156
+ const currentAllow = Array.isArray(permissions.allow) ? permissions.allow.filter((item) => typeof item === "string") : [];
157
+ const nextAllow = [...currentAllow];
158
+ for (const rule of CLAUDE_CADRE_ALLOW_RULES) {
159
+ if (!nextAllow.includes(rule)) nextAllow.push(rule);
160
+ }
161
+ const changed = nextAllow.length !== currentAllow.length || !isRecord(settings.permissions) || !Array.isArray(permissions.allow);
162
+ if (changed) {
163
+ settings.permissions = { ...permissions, allow: nextAllow };
164
+ import_node_fs.default.mkdirSync(import_node_path.default.dirname(file), { recursive: true });
165
+ import_node_fs.default.writeFileSync(file, `${JSON.stringify(settings, null, 2)}
166
+ `);
167
+ }
168
+ return { ok: true, target: "claude", path: file, changed, configured: true, rules: [...CLAUDE_CADRE_ALLOW_RULES] };
169
+ }
170
+ function checkClaudeApprovals() {
171
+ const file = approvalConfigPath("claude");
172
+ const parsed = readClaudeSettings(file);
173
+ if (!parsed.ok) return parsed.result;
174
+ const permissions = isRecord(parsed.settings.permissions) ? parsed.settings.permissions : {};
175
+ const allow = Array.isArray(permissions.allow) ? permissions.allow.filter((item) => typeof item === "string") : [];
176
+ const missing = CLAUDE_CADRE_ALLOW_RULES.filter((rule) => !allow.includes(rule));
177
+ const result = {
178
+ ok: missing.length === 0,
179
+ target: "claude",
180
+ path: file,
181
+ changed: false,
182
+ configured: missing.length === 0,
183
+ rules: missing.length === 0 ? [...CLAUDE_CADRE_ALLOW_RULES] : missing
184
+ };
185
+ if (missing.length > 0) result.error = `missing Claude Cadre tool allow rules: ${missing.join(", ")}`;
186
+ return result;
187
+ }
188
+ function readClaudeSettings(file) {
189
+ if (!import_node_fs.default.existsSync(file)) return { ok: true, settings: {} };
190
+ try {
191
+ const parsed = JSON.parse(import_node_fs.default.readFileSync(file, "utf8"));
192
+ if (isRecord(parsed)) return { ok: true, settings: parsed };
193
+ return {
194
+ ok: false,
195
+ result: { ok: false, target: "claude", path: file, changed: false, configured: false, rules: [...CLAUDE_CADRE_ALLOW_RULES], error: `${file} must contain a JSON object` }
196
+ };
197
+ } catch (error) {
198
+ return {
199
+ ok: false,
200
+ result: {
201
+ ok: false,
202
+ target: "claude",
203
+ path: file,
204
+ changed: false,
205
+ configured: false,
206
+ rules: [...CLAUDE_CADRE_ALLOW_RULES],
207
+ error: error instanceof Error ? error.message : String(error)
208
+ }
209
+ };
210
+ }
211
+ }
212
+ function isRecord(value) {
213
+ return typeof value === "object" && value !== null && !Array.isArray(value);
214
+ }
215
+
216
+ // src/cli/install.ts
34
217
  var PACKAGE_PLUGIN_NAME = "cadre";
35
218
  var PACKAGE_DISPLAY_NAME = "Cadre";
36
219
  var MARKETPLACE_PLUGIN_SOURCE = "./plugins/cadre";
@@ -52,7 +235,7 @@ function parseInstall(argv) {
52
235
  check: false,
53
236
  force: false,
54
237
  yes: false,
55
- cadreHome: process.env.CADRE_HOME || import_node_path.default.join(import_node_os.default.homedir(), ".cadre")
238
+ cadreHome: process.env.CADRE_HOME || import_node_path2.default.join(import_node_os2.default.homedir(), ".cadre")
56
239
  };
57
240
  for (let index = 0; index < argv.length; index += 1) {
58
241
  const arg = argv[index];
@@ -73,7 +256,7 @@ function parseInstall(argv) {
73
256
  } else if (arg === "--home") {
74
257
  const value = argv[index + 1];
75
258
  if (!value) throw new Error("--home requires a path");
76
- parsed.cadreHome = import_node_path.default.resolve(value);
259
+ parsed.cadreHome = import_node_path2.default.resolve(value);
77
260
  index += 1;
78
261
  } else {
79
262
  throw new Error(`Unknown install option: ${arg}`);
@@ -82,11 +265,11 @@ function parseInstall(argv) {
82
265
  return parsed;
83
266
  }
84
267
  function runtimePaths() {
85
- const runtimeRoot = import_node_path.default.resolve(__dirname, "..");
268
+ const runtimeRoot = import_node_path2.default.resolve(__dirname, "..");
86
269
  return {
87
270
  runtimeRoot,
88
271
  nodePath: process.execPath,
89
- mcpServer: import_node_path.default.join(runtimeRoot, "scripts", "mcp", "cadre-server.js")
272
+ mcpServer: import_node_path2.default.join(runtimeRoot, "scripts", "mcp", "cadre-server.js")
90
273
  };
91
274
  }
92
275
  function commandExists(command) {
@@ -99,16 +282,16 @@ function selectedTargets(options) {
99
282
  return ["codex", "claude"].filter((target) => commandExists(target));
100
283
  }
101
284
  function targetPaths(home, target) {
102
- const marketplaceRoot = import_node_path.default.join(home, "marketplaces", target);
285
+ const marketplaceRoot = import_node_path2.default.join(home, "marketplaces", target);
103
286
  return {
104
- pluginRoot: import_node_path.default.join(marketplaceRoot, "plugins", PACKAGE_PLUGIN_NAME),
287
+ pluginRoot: import_node_path2.default.join(marketplaceRoot, "plugins", PACKAGE_PLUGIN_NAME),
105
288
  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")
289
+ marketplaceFile: target === "codex" ? import_node_path2.default.join(marketplaceRoot, ".agents", "plugins", "marketplace.json") : import_node_path2.default.join(marketplaceRoot, ".claude-plugin", "marketplace.json")
107
290
  };
108
291
  }
109
292
  function readPackageMetadata(runtimeRoot) {
110
293
  try {
111
- const json = JSON.parse(import_node_fs.default.readFileSync(import_node_path.default.join(runtimeRoot, "package.json"), "utf8"));
294
+ const json = JSON.parse(import_node_fs2.default.readFileSync(import_node_path2.default.join(runtimeRoot, "package.json"), "utf8"));
112
295
  return {
113
296
  version: typeof json.version === "string" ? json.version : "0.0.0",
114
297
  description: typeof json.description === "string" ? json.description : "MCP-first Cadre workflows.",
@@ -198,24 +381,24 @@ function marketplace(target, runtime) {
198
381
  };
199
382
  }
200
383
  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)}
384
+ import_node_fs2.default.mkdirSync(import_node_path2.default.dirname(file), { recursive: true });
385
+ import_node_fs2.default.writeFileSync(file, `${JSON.stringify(value, null, 2)}
203
386
  `);
204
387
  }
205
388
  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}
389
+ import_node_fs2.default.mkdirSync(import_node_path2.default.dirname(file), { recursive: true });
390
+ import_node_fs2.default.writeFileSync(file, text.endsWith("\n") ? text : `${text}
208
391
  `);
209
392
  }
210
393
  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);
394
+ import_node_fs2.default.rmSync(paths.pluginRoot, { recursive: true, force: true });
395
+ writeText(import_node_path2.default.join(paths.pluginRoot, "skills", "cadre", "SKILL.md"), skillShim);
213
396
  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));
397
+ writeJson(import_node_path2.default.join(paths.pluginRoot, ".codex-plugin", "plugin.json"), pluginManifest(target, runtime));
398
+ writeJson(import_node_path2.default.join(paths.pluginRoot, ".mcp.json"), mcpConfig(runtime));
216
399
  } 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));
400
+ writeJson(import_node_path2.default.join(paths.pluginRoot, ".claude-plugin", "plugin.json"), pluginManifest(target, runtime));
401
+ writeJson(import_node_path2.default.join(paths.pluginRoot, "mcp-config.json"), mcpConfig(runtime));
219
402
  }
220
403
  writeJson(paths.marketplaceFile, marketplace(target, runtime));
221
404
  }
@@ -228,7 +411,8 @@ function installCommands(target, paths, scope) {
228
411
  }
229
412
  return [
230
413
  { command: "claude", args: ["plugin", "marketplace", "add", "--scope", scope, paths.marketplaceRoot] },
231
- { command: "claude", args: ["plugin", "install", "--scope", scope, "cadre@cadre"] }
414
+ { command: "claude", args: ["plugin", "install", "--scope", scope, "cadre@cadre"] },
415
+ { command: "claude", args: ["plugin", "update", "--scope", scope, "cadre@cadre"] }
232
416
  ];
233
417
  }
234
418
  function runCommand(plan) {
@@ -236,11 +420,11 @@ function runCommand(plan) {
236
420
  return { ok: result.status === 0, status: result.status, stderr: result.stderr || "" };
237
421
  }
238
422
  function assertNoThinPluginPayload(paths) {
239
- const forbidden = ["assets", "agents", "scripts"].filter((name) => import_node_fs.default.existsSync(import_node_path.default.join(paths.pluginRoot, name)));
423
+ const forbidden = ["assets", "agents", "scripts"].filter((name) => import_node_fs2.default.existsSync(import_node_path2.default.join(paths.pluginRoot, name)));
240
424
  return forbidden.map((name) => `${paths.pluginRoot}/${name}`);
241
425
  }
242
426
  function pingMcp(runtime) {
243
- if (!import_node_fs.default.existsSync(runtime.mcpServer)) return { ok: false, reason: `missing MCP server: ${runtime.mcpServer}` };
427
+ if (!import_node_fs2.default.existsSync(runtime.mcpServer)) return { ok: false, reason: `missing MCP server: ${runtime.mcpServer}` };
244
428
  const request = {
245
429
  jsonrpc: "2.0",
246
430
  id: 1,
@@ -269,15 +453,15 @@ function pingMcp(runtime) {
269
453
  }
270
454
  function checkTarget(target, paths, runtime) {
271
455
  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}`);
456
+ const skill = import_node_path2.default.join(paths.pluginRoot, "skills", "cadre", "SKILL.md");
457
+ if (!import_node_fs2.default.existsSync(skill)) errors.push(`missing ${skill}`);
458
+ const manifest = target === "codex" ? import_node_path2.default.join(paths.pluginRoot, ".codex-plugin", "plugin.json") : import_node_path2.default.join(paths.pluginRoot, ".claude-plugin", "plugin.json");
459
+ const mcp = target === "codex" ? import_node_path2.default.join(paths.pluginRoot, ".mcp.json") : import_node_path2.default.join(paths.pluginRoot, "mcp-config.json");
460
+ if (!import_node_fs2.default.existsSync(manifest)) errors.push(`missing ${manifest}`);
461
+ if (!import_node_fs2.default.existsSync(mcp)) errors.push(`missing ${mcp}`);
278
462
  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"));
463
+ if (import_node_fs2.default.existsSync(mcp)) {
464
+ const config = JSON.parse(import_node_fs2.default.readFileSync(mcp, "utf8"));
281
465
  const server = config.mcpServers?.cadre;
282
466
  if (server?.command !== runtime.nodePath) errors.push(`${mcp} does not point at the current Node runtime`);
283
467
  if (server?.args?.[0] !== runtime.mcpServer) errors.push(`${mcp} does not point at ${runtime.mcpServer}`);
@@ -313,10 +497,18 @@ function runInstall(argv, context) {
313
497
  const commands = installCommands(target, paths, options.scope);
314
498
  if (options.dryRun) {
315
499
  printPlan(target, paths, commands);
500
+ process.stdout.write(`Would configure: ${approvalSummary(target)}
501
+ `);
316
502
  continue;
317
503
  }
318
504
  if (!options.check) writeThinPlugin(target, paths, runtime, context.skillShim);
319
505
  const errors = checkTarget(target, paths, runtime);
506
+ if (!options.check) {
507
+ const approvals = bootstrapClientApprovals(target);
508
+ if (!approvals.ok) errors.push(`${target} approval bootstrap failed: ${approvals.error || approvals.path}`);
509
+ }
510
+ const approvalCheck = checkClientApprovals(target);
511
+ if (!approvalCheck.ok) errors.push(`${target} approval check failed: ${approvalCheck.error || approvalCheck.path}`);
320
512
  if (errors.length > 0) {
321
513
  ok = false;
322
514
  for (const error of errors) process.stderr.write(`${error}
@@ -325,6 +517,8 @@ function runInstall(argv, context) {
325
517
  }
326
518
  if (options.check) {
327
519
  process.stdout.write(`Cadre ${target} plugin is installed and points at ${runtime.mcpServer}
520
+ `);
521
+ process.stdout.write(`Cadre ${target} MCP tool approvals are configured in ${approvalCheck.path}
328
522
  `);
329
523
  continue;
330
524
  }
@@ -342,7 +536,7 @@ function runInstall(argv, context) {
342
536
  `);
343
537
  }
344
538
  }
345
- if (ok) process.stdout.write(`Installed Cadre ${target} plugin through ${paths.marketplaceRoot}
539
+ if (ok) process.stdout.write(`Installed Cadre ${target} plugin through ${paths.marketplaceRoot}; MCP tool approvals configured in ${approvalCheck.path}
346
540
  `);
347
541
  }
348
542
  return ok ? 0 : 1;