cadre-ai 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -13
- package/package.json +2 -4
- package/scripts/cadre-cli.js +232 -34
- package/scripts/cadre-core.js +9039 -6688
- package/scripts/cadre-lsp-review.js +177 -50
- package/scripts/cadre-lsp-setup.js +158 -29
- package/scripts/mcp/cadre-server.js +11122 -8055
- package/scripts/cadre-job-runner.js +0 -3355
- package/scripts/cadre-lsp-daemon.js +0 -1212
|
@@ -42,11 +42,11 @@ __export(cadre_lsp_setup_exports, {
|
|
|
42
42
|
scanFiles: () => scanFiles
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(cadre_lsp_setup_exports);
|
|
45
|
-
var
|
|
45
|
+
var import_node_path5 = __toESM(require("node:path"));
|
|
46
46
|
|
|
47
47
|
// src/lsp/setup-recommender.ts
|
|
48
|
-
var
|
|
49
|
-
var
|
|
48
|
+
var import_node_fs3 = __toESM(require("node:fs"));
|
|
49
|
+
var import_node_path4 = __toESM(require("node:path"));
|
|
50
50
|
var import_node_child_process2 = require("node:child_process");
|
|
51
51
|
|
|
52
52
|
// src/guards.ts
|
|
@@ -57,13 +57,140 @@ function asJsonObject(value) {
|
|
|
57
57
|
return isRecord(value) ? value : {};
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
// src/
|
|
60
|
+
// src/infrastructure/project-control-file.ts
|
|
61
61
|
var import_node_fs = __toESM(require("node:fs"));
|
|
62
|
-
var
|
|
62
|
+
var import_node_path = __toESM(require("node:path"));
|
|
63
|
+
var import_node_crypto = require("node:crypto");
|
|
64
|
+
function errorMessage(error) {
|
|
65
|
+
return error instanceof Error ? error.message : String(error);
|
|
66
|
+
}
|
|
67
|
+
function canonicalProjectRoot(root) {
|
|
68
|
+
try {
|
|
69
|
+
const canonical = import_node_fs.default.realpathSync(import_node_path.default.resolve(root));
|
|
70
|
+
return import_node_fs.default.statSync(canonical).isDirectory() ? canonical : null;
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function requestedSegments(requested) {
|
|
76
|
+
if (!requested || requested.includes("\0") || import_node_path.default.posix.isAbsolute(requested) || import_node_path.default.win32.isAbsolute(requested)) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const segments = requested.replace(/\\/g, "/").split("/");
|
|
80
|
+
if (segments.some((segment) => !segment || segment === "." || segment === "..")) return null;
|
|
81
|
+
return segments;
|
|
82
|
+
}
|
|
83
|
+
function lstatIfPresent(file) {
|
|
84
|
+
try {
|
|
85
|
+
return import_node_fs.default.lstatSync(file);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (error.code === "ENOENT") return null;
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function safeExistingControlPlane(controlDir) {
|
|
92
|
+
try {
|
|
93
|
+
const stat = lstatIfPresent(controlDir);
|
|
94
|
+
if (!stat) return null;
|
|
95
|
+
if (stat.isSymbolicLink()) return { ok: false, error: "Cadre config directory must not be a symbolic link" };
|
|
96
|
+
if (!stat.isDirectory()) return { ok: false, error: "Cadre config directory is not a directory" };
|
|
97
|
+
return null;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
return { ok: false, error: `Cannot inspect Cadre config directory: ${errorMessage(error)}` };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function safeExistingConfigFile(file) {
|
|
103
|
+
try {
|
|
104
|
+
const stat = lstatIfPresent(file);
|
|
105
|
+
if (!stat) return null;
|
|
106
|
+
if (stat.isSymbolicLink()) return { ok: false, error: "Cadre config file must not be a symbolic link" };
|
|
107
|
+
if (!stat.isFile()) return { ok: false, error: "Cadre config path is not a regular file" };
|
|
108
|
+
return null;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
return { ok: false, error: `Cannot inspect Cadre config file: ${errorMessage(error)}` };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function resolveProjectControlJsonPath(root, requested, defaultRelative) {
|
|
114
|
+
const canonicalRoot = canonicalProjectRoot(root);
|
|
115
|
+
if (!canonicalRoot) return { ok: false, error: "Project root does not exist or is not a directory" };
|
|
116
|
+
const relativeInput = requested || defaultRelative;
|
|
117
|
+
const segments = requestedSegments(relativeInput);
|
|
118
|
+
const defaultSegments = requestedSegments(defaultRelative);
|
|
119
|
+
const defaultName = defaultSegments?.length === 2 && defaultSegments[0] === "cadre" ? defaultSegments[1] : "";
|
|
120
|
+
const defaultStem = import_node_path.default.basename(defaultName, ".json");
|
|
121
|
+
const requestedName = segments?.[1] || "";
|
|
122
|
+
const namespaceMatch = requestedName === defaultName || requestedName.startsWith(`${defaultStem}-`) && requestedName.length > `${defaultStem}-.json`.length;
|
|
123
|
+
if (!segments || segments.length !== 2 || segments[0] !== "cadre" || import_node_path.default.extname(requestedName).toLowerCase() !== ".json" || !namespaceMatch) {
|
|
124
|
+
return {
|
|
125
|
+
ok: false,
|
|
126
|
+
error: `Cadre config must be ${defaultRelative} or a relative cadre/${defaultStem}-*.json path without traversal`
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const controlDir = import_node_path.default.join(canonicalRoot, "cadre");
|
|
130
|
+
const file = import_node_path.default.join(controlDir, segments[1]);
|
|
131
|
+
const controlError = safeExistingControlPlane(controlDir);
|
|
132
|
+
if (controlError) return controlError;
|
|
133
|
+
const fileError = safeExistingConfigFile(file);
|
|
134
|
+
if (fileError) return fileError;
|
|
135
|
+
return {
|
|
136
|
+
ok: true,
|
|
137
|
+
root: canonicalRoot,
|
|
138
|
+
file,
|
|
139
|
+
relative: `cadre/${segments[1]}`,
|
|
140
|
+
controlDir
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function writeProjectControlJson(root, requested, defaultRelative, value) {
|
|
144
|
+
const initial = resolveProjectControlJsonPath(root, requested, defaultRelative);
|
|
145
|
+
if (!initial.ok) return initial;
|
|
146
|
+
try {
|
|
147
|
+
if (!import_node_fs.default.existsSync(initial.controlDir)) import_node_fs.default.mkdirSync(initial.controlDir, { mode: 448 });
|
|
148
|
+
} catch (error) {
|
|
149
|
+
return { ok: false, error: `Cannot create Cadre config directory: ${errorMessage(error)}` };
|
|
150
|
+
}
|
|
151
|
+
const resolved = resolveProjectControlJsonPath(root, requested, defaultRelative);
|
|
152
|
+
if (!resolved.ok) return resolved;
|
|
153
|
+
const temporary = import_node_path.default.join(resolved.controlDir, `.${import_node_path.default.basename(resolved.file)}.${(0, import_node_crypto.randomUUID)()}.tmp`);
|
|
154
|
+
let descriptor = null;
|
|
155
|
+
try {
|
|
156
|
+
const noFollow = import_node_fs.default.constants.O_NOFOLLOW || 0;
|
|
157
|
+
descriptor = import_node_fs.default.openSync(
|
|
158
|
+
temporary,
|
|
159
|
+
import_node_fs.default.constants.O_CREAT | import_node_fs.default.constants.O_EXCL | import_node_fs.default.constants.O_WRONLY | noFollow,
|
|
160
|
+
384
|
|
161
|
+
);
|
|
162
|
+
import_node_fs.default.writeFileSync(descriptor, `${JSON.stringify(value, null, 2)}
|
|
163
|
+
`, "utf8");
|
|
164
|
+
import_node_fs.default.fsyncSync(descriptor);
|
|
165
|
+
import_node_fs.default.closeSync(descriptor);
|
|
166
|
+
descriptor = null;
|
|
167
|
+
const finalCheck = resolveProjectControlJsonPath(root, requested, defaultRelative);
|
|
168
|
+
if (!finalCheck.ok) return finalCheck;
|
|
169
|
+
import_node_fs.default.renameSync(temporary, finalCheck.file);
|
|
170
|
+
return finalCheck;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
return { ok: false, error: `Cannot write Cadre config: ${errorMessage(error)}` };
|
|
173
|
+
} finally {
|
|
174
|
+
if (descriptor !== null) {
|
|
175
|
+
try {
|
|
176
|
+
import_node_fs.default.closeSync(descriptor);
|
|
177
|
+
} catch {
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
import_node_fs.default.rmSync(temporary, { force: true });
|
|
182
|
+
} catch {
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/lsp/language-registry.ts
|
|
188
|
+
var import_node_fs2 = __toESM(require("node:fs"));
|
|
189
|
+
var import_node_path3 = __toESM(require("node:path"));
|
|
63
190
|
var import_node_child_process = require("node:child_process");
|
|
64
191
|
|
|
65
192
|
// src/lsp/ignore-policy.ts
|
|
66
|
-
var
|
|
193
|
+
var import_node_path2 = __toESM(require("node:path"));
|
|
67
194
|
var DEFAULT_IGNORES = /* @__PURE__ */ new Set([
|
|
68
195
|
".git",
|
|
69
196
|
".hg",
|
|
@@ -115,11 +242,11 @@ var DEFAULT_IGNORE_PATHS = [
|
|
|
115
242
|
"plugins/cadre-antigravity"
|
|
116
243
|
];
|
|
117
244
|
function normalizeRel(file) {
|
|
118
|
-
return file.split(
|
|
245
|
+
return file.split(import_node_path2.default.sep).join("/");
|
|
119
246
|
}
|
|
120
247
|
function shouldIgnore(root, fullPath, name) {
|
|
121
248
|
if (DEFAULT_IGNORES.has(name)) return true;
|
|
122
|
-
const rel = normalizeRel(
|
|
249
|
+
const rel = normalizeRel(import_node_path2.default.relative(root, fullPath));
|
|
123
250
|
return DEFAULT_IGNORE_PATHS.some(
|
|
124
251
|
(ignored) => rel === ignored || rel.startsWith(`${ignored}/`)
|
|
125
252
|
);
|
|
@@ -181,8 +308,8 @@ var LANGUAGE_RULES = [
|
|
|
181
308
|
function normalizeWorkspaceFile(root, rel) {
|
|
182
309
|
const normalized = rel.replace(/\r/g, "").trim();
|
|
183
310
|
if (!normalized) return null;
|
|
184
|
-
const full =
|
|
185
|
-
if (shouldIgnore(root, full,
|
|
311
|
+
const full = import_node_path3.default.join(root, normalized);
|
|
312
|
+
if (shouldIgnore(root, full, import_node_path3.default.basename(normalized))) return null;
|
|
186
313
|
return normalized;
|
|
187
314
|
}
|
|
188
315
|
function gitWorkspaceFiles(root) {
|
|
@@ -199,18 +326,18 @@ function walkWorkspaceFiles(root) {
|
|
|
199
326
|
const visit = (dir) => {
|
|
200
327
|
let entries;
|
|
201
328
|
try {
|
|
202
|
-
entries =
|
|
329
|
+
entries = import_node_fs2.default.readdirSync(dir, { withFileTypes: true });
|
|
203
330
|
} catch {
|
|
204
331
|
return;
|
|
205
332
|
}
|
|
206
333
|
for (const entry of entries) {
|
|
207
|
-
const full =
|
|
334
|
+
const full = import_node_path3.default.join(dir, entry.name);
|
|
208
335
|
if (shouldIgnore(root, full, entry.name)) continue;
|
|
209
336
|
if (entry.isDirectory()) {
|
|
210
337
|
visit(full);
|
|
211
338
|
continue;
|
|
212
339
|
}
|
|
213
|
-
if (entry.isFile()) files.push(
|
|
340
|
+
if (entry.isFile()) files.push(import_node_path3.default.relative(root, full).split(import_node_path3.default.sep).join("/"));
|
|
214
341
|
}
|
|
215
342
|
};
|
|
216
343
|
visit(root);
|
|
@@ -226,10 +353,10 @@ function scanWorkspaceFiles(root) {
|
|
|
226
353
|
const filenameCounts = /* @__PURE__ */ new Map();
|
|
227
354
|
const filenameSamples = /* @__PURE__ */ new Map();
|
|
228
355
|
for (const rel of listWorkspaceFiles(root)) {
|
|
229
|
-
const full =
|
|
230
|
-
const name =
|
|
356
|
+
const full = import_node_path3.default.join(root, rel);
|
|
357
|
+
const name = import_node_path3.default.basename(rel);
|
|
231
358
|
if (shouldIgnore(root, full, name)) continue;
|
|
232
|
-
const ext =
|
|
359
|
+
const ext = import_node_path3.default.extname(name).toLowerCase();
|
|
233
360
|
if (ext) {
|
|
234
361
|
counts.set(ext, (counts.get(ext) ?? 0) + 1);
|
|
235
362
|
const extSamples = samples.get(ext) ?? [];
|
|
@@ -246,6 +373,7 @@ function scanWorkspaceFiles(root) {
|
|
|
246
373
|
}
|
|
247
374
|
|
|
248
375
|
// src/lsp/setup-recommender.ts
|
|
376
|
+
var DEFAULT_LSP_CONFIG = "cadre/lsp.json";
|
|
249
377
|
function usage() {
|
|
250
378
|
console.log(`Usage: node <cadre-lsp-setup.js> [--root DIR] [--config cadre/lsp.json] [--write] [--json]
|
|
251
379
|
|
|
@@ -277,8 +405,10 @@ function parseArgs(argv) {
|
|
|
277
405
|
throw new Error(`Unknown argument: ${arg}`);
|
|
278
406
|
}
|
|
279
407
|
}
|
|
280
|
-
const root =
|
|
281
|
-
|
|
408
|
+
const root = import_node_path4.default.resolve(args.root);
|
|
409
|
+
const configPath = resolveProjectControlJsonPath(root, args.config, DEFAULT_LSP_CONFIG);
|
|
410
|
+
if (!configPath.ok) throw new Error(configPath.error);
|
|
411
|
+
return { ...args, root, config: configPath.relative, configPath: configPath.file };
|
|
282
412
|
}
|
|
283
413
|
function shellQuote(value) {
|
|
284
414
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
@@ -309,7 +439,7 @@ function normalizeServer(value) {
|
|
|
309
439
|
}
|
|
310
440
|
function loadConfig(configPath) {
|
|
311
441
|
try {
|
|
312
|
-
const parsed = JSON.parse(
|
|
442
|
+
const parsed = JSON.parse(import_node_fs3.default.readFileSync(configPath, "utf8"));
|
|
313
443
|
const config = asJsonObject(parsed);
|
|
314
444
|
const servers = Array.isArray(config.servers) ? config.servers.map(normalizeServer).filter((server) => server !== null) : [];
|
|
315
445
|
return { ...config, servers };
|
|
@@ -317,10 +447,9 @@ function loadConfig(configPath) {
|
|
|
317
447
|
return { servers: [] };
|
|
318
448
|
}
|
|
319
449
|
}
|
|
320
|
-
function saveConfig(
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
`);
|
|
450
|
+
function saveConfig(root, requested, config) {
|
|
451
|
+
const written = writeProjectControlJson(root, requested, DEFAULT_LSP_CONFIG, config);
|
|
452
|
+
if (!written.ok) throw new Error(written.error);
|
|
324
453
|
}
|
|
325
454
|
function recommend(root) {
|
|
326
455
|
const scan = scanFiles(root);
|
|
@@ -356,10 +485,10 @@ function serverKey(server) {
|
|
|
356
485
|
}
|
|
357
486
|
function workspaceFolders(root) {
|
|
358
487
|
const folders = [{ name: ".", path: "." }];
|
|
359
|
-
const reposPath =
|
|
488
|
+
const reposPath = import_node_path4.default.join(root, "cadre", "repos.json");
|
|
360
489
|
let repos = {};
|
|
361
490
|
try {
|
|
362
|
-
repos = asJsonObject(JSON.parse(
|
|
491
|
+
repos = asJsonObject(JSON.parse(import_node_fs3.default.readFileSync(reposPath, "utf8")));
|
|
363
492
|
} catch {
|
|
364
493
|
return folders;
|
|
365
494
|
}
|
|
@@ -408,13 +537,13 @@ function runCli() {
|
|
|
408
537
|
let added = [];
|
|
409
538
|
if (args.write) {
|
|
410
539
|
const merged = mergeConfig(config, recommendations, args.root);
|
|
411
|
-
saveConfig(args.
|
|
540
|
+
saveConfig(args.root, args.config, merged.config);
|
|
412
541
|
written = true;
|
|
413
542
|
added = merged.added;
|
|
414
543
|
}
|
|
415
544
|
const result = {
|
|
416
545
|
root: args.root,
|
|
417
|
-
config:
|
|
546
|
+
config: args.config,
|
|
418
547
|
recommended: recommendations,
|
|
419
548
|
missingFromConfig: missingFromConfig.map((rec) => rec.id),
|
|
420
549
|
missingCommands: missingCommands.map((rec) => ({
|
|
@@ -443,14 +572,14 @@ function runCli() {
|
|
|
443
572
|
if (!rec.available) console.log(` install: ${rec.install}`);
|
|
444
573
|
}
|
|
445
574
|
if (written) {
|
|
446
|
-
console.log(`Updated ${
|
|
575
|
+
console.log(`Updated ${args.config}; added: ${added.join(", ") || "none"}.`);
|
|
447
576
|
} else if (missingFromConfig.length > 0) {
|
|
448
577
|
console.log("Run with --write to append missing server entries to cadre/lsp.json.");
|
|
449
578
|
}
|
|
450
579
|
}
|
|
451
580
|
|
|
452
581
|
// src/cadre-lsp-setup.ts
|
|
453
|
-
if (["cadre-lsp-setup.js", "cadre-lsp-setup.ts"].includes(
|
|
582
|
+
if (["cadre-lsp-setup.js", "cadre-lsp-setup.ts"].includes(import_node_path5.default.basename(process.argv[1] || ""))) {
|
|
454
583
|
try {
|
|
455
584
|
runCli();
|
|
456
585
|
} catch (error) {
|