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.
- package/.claude-plugin/plugin.json +10 -0
- package/.codex-plugin/plugin.json +19 -0
- package/.mcp.codex.json +9 -0
- package/.mcp.json +8 -0
- package/LICENSE +21 -202
- package/README.md +353 -134
- package/agents/cadre-phase-worker.md +17 -0
- package/agents/cadre-task-worker.md +16 -0
- package/dist/cadre-cli.mjs +2756 -0
- package/dist/cadre-mcp.mjs +33680 -0
- package/marketplace/claude.json +16 -0
- package/marketplace/codex.json +20 -0
- package/package.json +36 -32
- package/skills/archive/SKILL.md +28 -0
- package/skills/archive/agents/openai.yaml +4 -0
- package/skills/create/SKILL.md +33 -0
- package/skills/create/agents/openai.yaml +4 -0
- package/skills/implement/SKILL.md +91 -0
- package/skills/implement/agents/openai.yaml +4 -0
- package/skills/refresh/SKILL.md +18 -0
- package/skills/refresh/agents/openai.yaml +4 -0
- package/skills/revert/SKILL.md +20 -0
- package/skills/revert/agents/openai.yaml +4 -0
- package/skills/review/SKILL.md +32 -0
- package/skills/review/agents/openai.yaml +4 -0
- package/skills/revise/SKILL.md +32 -0
- package/skills/revise/agents/openai.yaml +4 -0
- package/skills/status/SKILL.md +21 -0
- package/skills/status/agents/openai.yaml +4 -0
- package/skills/track/SKILL.md +33 -0
- package/skills/track/agents/openai.yaml +4 -0
- package/skills/wisp/SKILL.md +16 -0
- package/skills/wisp/agents/openai.yaml +4 -0
- package/templates/v1/init/archive/.gitkeep +1 -0
- package/templates/v1/init/guidelines.md +25 -0
- package/templates/v1/init/operations/.gitkeep +1 -0
- package/templates/v1/init/patterns/index.md +6 -0
- package/templates/v1/init/product.md +30 -0
- package/templates/v1/init/project.json +26 -0
- package/templates/v1/init/refreshes/.gitkeep +1 -0
- package/templates/v1/init/styleguides/general.md +14 -0
- package/templates/v1/init/styleguides/language.md +21 -0
- package/templates/v1/init/tech-stack.md +21 -0
- package/templates/v1/init/tracks/.gitkeep +1 -0
- package/templates/v1/init/tracks.md +6 -0
- package/templates/v1/init/workflow.md +163 -0
- package/templates/v1/project/archive-operation.json +15 -0
- package/templates/v1/project/pattern.md +20 -0
- package/templates/v1/project/refresh-operation.json +14 -0
- package/templates/v1/project/refresh.md +21 -0
- package/templates/v1/styleguides/dart.md +27 -0
- package/templates/v1/styleguides/flutter.md +27 -0
- package/templates/v1/styleguides/go.md +29 -0
- package/templates/v1/styleguides/gradle.md +28 -0
- package/templates/v1/styleguides/html-css.md +39 -0
- package/templates/v1/styleguides/index.md +27 -0
- package/templates/v1/styleguides/java.md +27 -0
- package/templates/v1/styleguides/javascript.md +27 -0
- package/templates/v1/styleguides/kotlin.md +26 -0
- package/templates/v1/styleguides/maven.md +28 -0
- package/templates/v1/styleguides/python.md +27 -0
- package/templates/v1/styleguides/react.md +28 -0
- package/templates/v1/styleguides/swift.md +27 -0
- package/templates/v1/styleguides/swiftui.md +27 -0
- package/templates/v1/styleguides/typescript.md +26 -0
- package/templates/v1/track/bug.md +14 -0
- package/templates/v1/track/execution.json +18 -0
- package/templates/v1/track/learning.md +39 -0
- package/templates/v1/track/plan.md +39 -0
- package/templates/v1/track/revert-operation.json +13 -0
- package/templates/v1/track/revise-operation.json +14 -0
- package/templates/v1/track/revision.md +36 -0
- package/templates/v1/track/spec.md +38 -0
- package/templates/v1/track/state.json +25 -0
- package/scripts/cadre-cli.js +0 -1076
- package/scripts/cadre-core.js +0 -15240
- package/scripts/cadre-lsp-review.js +0 -1194
- package/scripts/cadre-lsp-setup.js +0 -599
- package/scripts/mcp/cadre-server.js +0 -19013
|
@@ -1,599 +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
|
-
"use strict";
|
|
5
|
-
var __create = Object.create;
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name in all)
|
|
13
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from))
|
|
18
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
31
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
-
|
|
33
|
-
// src/cadre-lsp-setup.ts
|
|
34
|
-
var cadre_lsp_setup_exports = {};
|
|
35
|
-
__export(cadre_lsp_setup_exports, {
|
|
36
|
-
commandAvailability: () => commandAvailability,
|
|
37
|
-
loadConfig: () => loadConfig,
|
|
38
|
-
mergeConfig: () => mergeConfig,
|
|
39
|
-
parseArgs: () => parseArgs,
|
|
40
|
-
recommend: () => recommend,
|
|
41
|
-
runCli: () => runCli,
|
|
42
|
-
scanFiles: () => scanFiles
|
|
43
|
-
});
|
|
44
|
-
module.exports = __toCommonJS(cadre_lsp_setup_exports);
|
|
45
|
-
var import_node_path5 = __toESM(require("node:path"));
|
|
46
|
-
|
|
47
|
-
// src/lsp/setup-recommender.ts
|
|
48
|
-
var import_node_fs3 = __toESM(require("node:fs"));
|
|
49
|
-
var import_node_path4 = __toESM(require("node:path"));
|
|
50
|
-
var import_node_child_process2 = require("node:child_process");
|
|
51
|
-
|
|
52
|
-
// src/guards.ts
|
|
53
|
-
function isRecord(value) {
|
|
54
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
55
|
-
}
|
|
56
|
-
function asJsonObject(value) {
|
|
57
|
-
return isRecord(value) ? value : {};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// src/infrastructure/project-control-file.ts
|
|
61
|
-
var import_node_fs = __toESM(require("node:fs"));
|
|
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"));
|
|
190
|
-
var import_node_child_process = require("node:child_process");
|
|
191
|
-
|
|
192
|
-
// src/lsp/ignore-policy.ts
|
|
193
|
-
var import_node_path2 = __toESM(require("node:path"));
|
|
194
|
-
var DEFAULT_IGNORES = /* @__PURE__ */ new Set([
|
|
195
|
-
".git",
|
|
196
|
-
".hg",
|
|
197
|
-
".svn",
|
|
198
|
-
".worktrees",
|
|
199
|
-
".agents",
|
|
200
|
-
".claude",
|
|
201
|
-
".cache",
|
|
202
|
-
".codex",
|
|
203
|
-
".copilot",
|
|
204
|
-
".dart_tool",
|
|
205
|
-
".gemini",
|
|
206
|
-
".gradle",
|
|
207
|
-
".mypy_cache",
|
|
208
|
-
".pytest_cache",
|
|
209
|
-
".ruff_cache",
|
|
210
|
-
".serverless",
|
|
211
|
-
"node_modules",
|
|
212
|
-
"vendor",
|
|
213
|
-
"dist",
|
|
214
|
-
"build",
|
|
215
|
-
"coverage",
|
|
216
|
-
"out",
|
|
217
|
-
"target",
|
|
218
|
-
".next",
|
|
219
|
-
".nuxt",
|
|
220
|
-
".parcel-cache",
|
|
221
|
-
".svelte-kit",
|
|
222
|
-
".turbo",
|
|
223
|
-
".vite",
|
|
224
|
-
".venv",
|
|
225
|
-
"venv",
|
|
226
|
-
"__pycache__",
|
|
227
|
-
"__generated__",
|
|
228
|
-
"generated",
|
|
229
|
-
"gen",
|
|
230
|
-
"tmp",
|
|
231
|
-
"temp",
|
|
232
|
-
"logs",
|
|
233
|
-
"Pods",
|
|
234
|
-
"DerivedData",
|
|
235
|
-
".idea",
|
|
236
|
-
".vscode"
|
|
237
|
-
]);
|
|
238
|
-
var DEFAULT_IGNORE_PATHS = [
|
|
239
|
-
"plugins/cadre",
|
|
240
|
-
"plugins/cadre-claude",
|
|
241
|
-
"plugins/cadre-copilot",
|
|
242
|
-
"plugins/cadre-antigravity"
|
|
243
|
-
];
|
|
244
|
-
function normalizeRel(file) {
|
|
245
|
-
return file.split(import_node_path2.default.sep).join("/");
|
|
246
|
-
}
|
|
247
|
-
function shouldIgnore(root, fullPath, name) {
|
|
248
|
-
if (DEFAULT_IGNORES.has(name)) return true;
|
|
249
|
-
const rel = normalizeRel(import_node_path2.default.relative(root, fullPath));
|
|
250
|
-
return DEFAULT_IGNORE_PATHS.some(
|
|
251
|
-
(ignored) => rel === ignored || rel.startsWith(`${ignored}/`)
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// src/lsp/language-registry.ts
|
|
256
|
-
var LANGUAGE_RULES = [
|
|
257
|
-
{
|
|
258
|
-
id: "typescript",
|
|
259
|
-
label: "TypeScript / JavaScript",
|
|
260
|
-
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"],
|
|
261
|
-
command: "typescript-language-server",
|
|
262
|
-
args: ["--stdio"],
|
|
263
|
-
install: "npm install -g typescript-language-server typescript"
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
id: "python",
|
|
267
|
-
label: "Python",
|
|
268
|
-
extensions: [".py", ".pyi"],
|
|
269
|
-
command: "pyright-langserver",
|
|
270
|
-
args: ["--stdio"],
|
|
271
|
-
install: "npm install -g pyright"
|
|
272
|
-
},
|
|
273
|
-
{ id: "go", label: "Go", extensions: [".go"], command: "gopls", args: [], install: "go install golang.org/x/tools/gopls@latest" },
|
|
274
|
-
{ id: "rust", label: "Rust", extensions: [".rs"], command: "rust-analyzer", args: [], install: "rustup component add rust-analyzer" },
|
|
275
|
-
{ id: "java", label: "Java", extensions: [".java"], command: "jdtls", args: [], install: "brew install jdtls # or install Eclipse JDT LS for your platform" },
|
|
276
|
-
{ id: "kotlin", label: "Kotlin", extensions: [".kt", ".kts"], command: "kotlin-language-server", args: [], install: "brew install fwcd/kotlin-language-server/kotlin-language-server" },
|
|
277
|
-
{ id: "swift", label: "Swift", extensions: [".swift"], command: "sourcekit-lsp", args: [], install: "Install Xcode or Swift toolchain; sourcekit-lsp ships with it" },
|
|
278
|
-
{ id: "c-cpp", label: "C / C++ / Objective-C", extensions: [".c", ".h", ".cc", ".cpp", ".cxx", ".hpp", ".m", ".mm"], command: "clangd", args: [], install: "brew install llvm # or install clangd for your platform" },
|
|
279
|
-
{ id: "csharp", label: "C#", extensions: [".cs"], command: "csharp-ls", args: [], install: "dotnet tool install --global csharp-ls" },
|
|
280
|
-
{ id: "php", label: "PHP", extensions: [".php"], command: "intelephense", args: ["--stdio"], install: "npm install -g intelephense" },
|
|
281
|
-
{ id: "ruby", label: "Ruby", extensions: [".rb"], command: "ruby-lsp", args: [], install: "gem install ruby-lsp" },
|
|
282
|
-
{ id: "dart", label: "Dart / Flutter", extensions: [".dart"], command: "dart", args: ["language-server", "--protocol=lsp"], install: "Install the Dart or Flutter SDK and ensure `dart` is on PATH" },
|
|
283
|
-
{ id: "html", label: "HTML", extensions: [".html", ".htm"], command: "vscode-html-language-server", args: ["--stdio"], install: "npm install -g vscode-langservers-extracted" },
|
|
284
|
-
{ id: "css", label: "CSS / Sass / Less", extensions: [".css", ".scss", ".sass", ".less"], command: "vscode-css-language-server", args: ["--stdio"], install: "npm install -g vscode-langservers-extracted" },
|
|
285
|
-
{ id: "json", label: "JSON", extensions: [".json", ".jsonc"], command: "vscode-json-language-server", args: ["--stdio"], install: "npm install -g vscode-langservers-extracted" },
|
|
286
|
-
{ id: "yaml", label: "YAML", extensions: [".yaml", ".yml"], command: "yaml-language-server", args: ["--stdio"], install: "npm install -g yaml-language-server" },
|
|
287
|
-
{ id: "markdown", label: "Markdown", extensions: [".md", ".mdx"], command: "marksman", args: ["server"], install: "brew install marksman # or download Marksman for your platform" },
|
|
288
|
-
{ id: "toml", label: "TOML", extensions: [".toml"], command: "taplo", args: ["lsp", "stdio"], install: "cargo install taplo-cli --locked" },
|
|
289
|
-
{ id: "lua", label: "Lua", extensions: [".lua"], command: "lua-language-server", args: [], install: "brew install lua-language-server # or install LuaLS for your platform" },
|
|
290
|
-
{ id: "shell", label: "Shell", extensions: [".sh", ".bash", ".zsh", ".ksh"], command: "bash-language-server", args: ["start"], install: "npm install -g bash-language-server" },
|
|
291
|
-
{ id: "terraform", label: "Terraform / HCL", extensions: [".tf", ".tfvars", ".hcl"], command: "terraform-ls", args: ["serve"], install: "brew install hashicorp/tap/terraform-ls" },
|
|
292
|
-
{ id: "elixir", label: "Elixir", extensions: [".ex", ".exs"], command: "elixir-ls", args: [], install: "Install ElixirLS and ensure `elixir-ls` is on PATH" },
|
|
293
|
-
{ id: "scala", label: "Scala", extensions: [".scala", ".sc"], command: "metals", args: [], install: "coursier install metals" },
|
|
294
|
-
{ id: "clojure", label: "Clojure", extensions: [".clj", ".cljs", ".cljc", ".edn"], command: "clojure-lsp", args: [], install: "brew install clojure-lsp/brew/clojure-lsp-native" },
|
|
295
|
-
{ id: "haskell", label: "Haskell", extensions: [".hs", ".lhs"], command: "haskell-language-server-wrapper", args: ["--lsp"], install: "ghcup install hls" },
|
|
296
|
-
{ id: "ocaml", label: "OCaml", extensions: [".ml", ".mli"], command: "ocamllsp", args: [], install: "opam install ocaml-lsp-server" },
|
|
297
|
-
{ id: "zig", label: "Zig", extensions: [".zig"], command: "zls", args: [], install: "Install zls and ensure it is on PATH" },
|
|
298
|
-
{ id: "nix", label: "Nix", extensions: [".nix"], command: "nil", args: [], install: "nix profile install nixpkgs#nil" },
|
|
299
|
-
{ id: "elm", label: "Elm", extensions: [".elm"], command: "elm-language-server", args: ["--stdio"], install: "npm install -g @elm-tooling/elm-language-server" },
|
|
300
|
-
{ id: "vue", label: "Vue", extensions: [".vue"], command: "vue-language-server", args: ["--stdio"], install: "npm install -g @vue/language-server" },
|
|
301
|
-
{ id: "svelte", label: "Svelte", extensions: [".svelte"], command: "svelteserver", args: ["--stdio"], install: "npm install -g svelte-language-server" },
|
|
302
|
-
{ id: "dockerfile", label: "Dockerfile", extensions: [], filenames: ["Dockerfile", "Containerfile"], command: "docker-langserver", args: ["--stdio"], install: "npm install -g dockerfile-language-server-nodejs", languageIds: { Dockerfile: "dockerfile", Containerfile: "dockerfile" } },
|
|
303
|
-
{ id: "xml", label: "XML", extensions: [".xml", ".xsd", ".xsl", ".xslt"], command: "lemminx", args: [], install: "Install Eclipse LemMinX and ensure `lemminx` is on PATH" },
|
|
304
|
-
{ id: "graphql", label: "GraphQL", extensions: [".graphql", ".gql"], command: "graphql-lsp", args: ["server", "-m", "stream"], install: "npm install -g graphql-language-service-cli" },
|
|
305
|
-
{ id: "prisma", label: "Prisma", extensions: [".prisma"], command: "prisma-language-server", args: ["--stdio"], install: "npm install -g @prisma/language-server" },
|
|
306
|
-
{ id: "protobuf", label: "Protocol Buffers", extensions: [".proto"], command: "buf", args: ["beta", "lsp", "--timeout=0"], install: "brew install bufbuild/buf/buf" }
|
|
307
|
-
];
|
|
308
|
-
function normalizeWorkspaceFile(root, rel) {
|
|
309
|
-
const normalized = rel.replace(/\r/g, "").trim();
|
|
310
|
-
if (!normalized) return null;
|
|
311
|
-
const full = import_node_path3.default.join(root, normalized);
|
|
312
|
-
if (shouldIgnore(root, full, import_node_path3.default.basename(normalized))) return null;
|
|
313
|
-
return normalized;
|
|
314
|
-
}
|
|
315
|
-
function gitWorkspaceFiles(root) {
|
|
316
|
-
const result = (0, import_node_child_process.spawnSync)("git", ["ls-files", "-co", "--exclude-standard", "-z"], {
|
|
317
|
-
cwd: root,
|
|
318
|
-
encoding: "buffer",
|
|
319
|
-
maxBuffer: 30 * 1024 * 1024
|
|
320
|
-
});
|
|
321
|
-
if (result.status !== 0 || !result.stdout || result.stdout.length === 0) return [];
|
|
322
|
-
return result.stdout.toString("utf8").split("\0").map((item) => normalizeWorkspaceFile(root, item)).filter((item) => Boolean(item)).sort();
|
|
323
|
-
}
|
|
324
|
-
function walkWorkspaceFiles(root) {
|
|
325
|
-
const files = [];
|
|
326
|
-
const visit = (dir) => {
|
|
327
|
-
let entries;
|
|
328
|
-
try {
|
|
329
|
-
entries = import_node_fs2.default.readdirSync(dir, { withFileTypes: true });
|
|
330
|
-
} catch {
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
for (const entry of entries) {
|
|
334
|
-
const full = import_node_path3.default.join(dir, entry.name);
|
|
335
|
-
if (shouldIgnore(root, full, entry.name)) continue;
|
|
336
|
-
if (entry.isDirectory()) {
|
|
337
|
-
visit(full);
|
|
338
|
-
continue;
|
|
339
|
-
}
|
|
340
|
-
if (entry.isFile()) files.push(import_node_path3.default.relative(root, full).split(import_node_path3.default.sep).join("/"));
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
visit(root);
|
|
344
|
-
return files.sort();
|
|
345
|
-
}
|
|
346
|
-
function listWorkspaceFiles(root) {
|
|
347
|
-
const gitFiles = gitWorkspaceFiles(root);
|
|
348
|
-
return gitFiles.length > 0 ? gitFiles : walkWorkspaceFiles(root);
|
|
349
|
-
}
|
|
350
|
-
function scanWorkspaceFiles(root) {
|
|
351
|
-
const counts = /* @__PURE__ */ new Map();
|
|
352
|
-
const samples = /* @__PURE__ */ new Map();
|
|
353
|
-
const filenameCounts = /* @__PURE__ */ new Map();
|
|
354
|
-
const filenameSamples = /* @__PURE__ */ new Map();
|
|
355
|
-
for (const rel of listWorkspaceFiles(root)) {
|
|
356
|
-
const full = import_node_path3.default.join(root, rel);
|
|
357
|
-
const name = import_node_path3.default.basename(rel);
|
|
358
|
-
if (shouldIgnore(root, full, name)) continue;
|
|
359
|
-
const ext = import_node_path3.default.extname(name).toLowerCase();
|
|
360
|
-
if (ext) {
|
|
361
|
-
counts.set(ext, (counts.get(ext) ?? 0) + 1);
|
|
362
|
-
const extSamples = samples.get(ext) ?? [];
|
|
363
|
-
if (extSamples.length < 5) extSamples.push(rel);
|
|
364
|
-
samples.set(ext, extSamples);
|
|
365
|
-
}
|
|
366
|
-
const lower = name.toLowerCase();
|
|
367
|
-
filenameCounts.set(lower, (filenameCounts.get(lower) ?? 0) + 1);
|
|
368
|
-
const nameSamples = filenameSamples.get(lower) ?? [];
|
|
369
|
-
if (nameSamples.length < 5) nameSamples.push(rel);
|
|
370
|
-
filenameSamples.set(lower, nameSamples);
|
|
371
|
-
}
|
|
372
|
-
return { counts, samples, filenameCounts, filenameSamples };
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// src/lsp/setup-recommender.ts
|
|
376
|
-
var DEFAULT_LSP_CONFIG = "cadre/lsp.json";
|
|
377
|
-
function usage() {
|
|
378
|
-
console.log(`Usage: node <cadre-lsp-setup.js> [--root DIR] [--config cadre/lsp.json] [--write] [--json]
|
|
379
|
-
|
|
380
|
-
Scans the codebase, recommends language servers, detects whether the server
|
|
381
|
-
commands are installed, and optionally appends missing server entries to
|
|
382
|
-
cadre/lsp.json.`);
|
|
383
|
-
}
|
|
384
|
-
function parseArgs(argv) {
|
|
385
|
-
const args = {
|
|
386
|
-
root: process.cwd(),
|
|
387
|
-
config: "cadre/lsp.json",
|
|
388
|
-
write: false,
|
|
389
|
-
json: false
|
|
390
|
-
};
|
|
391
|
-
for (let i = 2; i < argv.length; i += 1) {
|
|
392
|
-
const arg = argv[i] ?? "";
|
|
393
|
-
if (arg === "--help" || arg === "-h") {
|
|
394
|
-
usage();
|
|
395
|
-
process.exit(0);
|
|
396
|
-
} else if (arg === "--write") {
|
|
397
|
-
args.write = true;
|
|
398
|
-
} else if (arg === "--json") {
|
|
399
|
-
args.json = true;
|
|
400
|
-
} else if (arg === "--root") {
|
|
401
|
-
args.root = argv[++i] ?? args.root;
|
|
402
|
-
} else if (arg === "--config") {
|
|
403
|
-
args.config = argv[++i] ?? args.config;
|
|
404
|
-
} else {
|
|
405
|
-
throw new Error(`Unknown argument: ${arg}`);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
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 };
|
|
412
|
-
}
|
|
413
|
-
function shellQuote(value) {
|
|
414
|
-
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
415
|
-
}
|
|
416
|
-
function commandAvailability(command) {
|
|
417
|
-
const result = (0, import_node_child_process2.spawnSync)("sh", ["-lc", `command -v ${shellQuote(command)}`], {
|
|
418
|
-
encoding: "utf8"
|
|
419
|
-
});
|
|
420
|
-
if (result.status === 0) {
|
|
421
|
-
return {
|
|
422
|
-
state: "available",
|
|
423
|
-
command,
|
|
424
|
-
path: result.stdout.trim().split(/\r?\n/)[0] || command
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
return {
|
|
428
|
-
state: "missing",
|
|
429
|
-
command,
|
|
430
|
-
message: (result.stderr || result.stdout || "Command not found on PATH").trim()
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
function scanFiles(root) {
|
|
434
|
-
return scanWorkspaceFiles(root);
|
|
435
|
-
}
|
|
436
|
-
function normalizeServer(value) {
|
|
437
|
-
if (!isRecord(value)) return null;
|
|
438
|
-
return asJsonObject(value);
|
|
439
|
-
}
|
|
440
|
-
function loadConfig(configPath) {
|
|
441
|
-
try {
|
|
442
|
-
const parsed = JSON.parse(import_node_fs3.default.readFileSync(configPath, "utf8"));
|
|
443
|
-
const config = asJsonObject(parsed);
|
|
444
|
-
const servers = Array.isArray(config.servers) ? config.servers.map(normalizeServer).filter((server) => server !== null) : [];
|
|
445
|
-
return { ...config, servers };
|
|
446
|
-
} catch {
|
|
447
|
-
return { servers: [] };
|
|
448
|
-
}
|
|
449
|
-
}
|
|
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);
|
|
453
|
-
}
|
|
454
|
-
function recommend(root) {
|
|
455
|
-
const scan = scanFiles(root);
|
|
456
|
-
return LANGUAGE_RULES.flatMap((rule) => {
|
|
457
|
-
const extensionFiles = rule.extensions.reduce(
|
|
458
|
-
(sum, ext) => sum + (scan.counts.get(ext) ?? 0),
|
|
459
|
-
0
|
|
460
|
-
);
|
|
461
|
-
const filenameFiles = (rule.filenames ?? []).reduce(
|
|
462
|
-
(sum, filename) => sum + (scan.filenameCounts.get(filename.toLowerCase()) ?? 0),
|
|
463
|
-
0
|
|
464
|
-
);
|
|
465
|
-
const files = extensionFiles + filenameFiles;
|
|
466
|
-
if (files === 0) return [];
|
|
467
|
-
const sampleFiles = [
|
|
468
|
-
...rule.extensions.flatMap((ext) => scan.samples.get(ext) ?? []),
|
|
469
|
-
...(rule.filenames ?? []).flatMap((filename) => scan.filenameSamples.get(filename.toLowerCase()) ?? [])
|
|
470
|
-
];
|
|
471
|
-
const availability = commandAvailability(rule.command);
|
|
472
|
-
return [{
|
|
473
|
-
...rule,
|
|
474
|
-
files,
|
|
475
|
-
samples: sampleFiles.slice(0, 8),
|
|
476
|
-
available: availability.state === "available",
|
|
477
|
-
availability
|
|
478
|
-
}];
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
function serverKey(server) {
|
|
482
|
-
const id = typeof server.id === "string" ? server.id : "";
|
|
483
|
-
const command = typeof server.command === "string" ? server.command : "";
|
|
484
|
-
return id || command;
|
|
485
|
-
}
|
|
486
|
-
function workspaceFolders(root) {
|
|
487
|
-
const folders = [{ name: ".", path: "." }];
|
|
488
|
-
const reposPath = import_node_path4.default.join(root, "cadre", "repos.json");
|
|
489
|
-
let repos = {};
|
|
490
|
-
try {
|
|
491
|
-
repos = asJsonObject(JSON.parse(import_node_fs3.default.readFileSync(reposPath, "utf8")));
|
|
492
|
-
} catch {
|
|
493
|
-
return folders;
|
|
494
|
-
}
|
|
495
|
-
if (repos.mode !== "polyrepo" || !Array.isArray(repos.repos)) return folders;
|
|
496
|
-
for (const raw of repos.repos) {
|
|
497
|
-
const repo = asJsonObject(raw);
|
|
498
|
-
if (repo.enabled === false || typeof repo.name !== "string" || typeof repo.submodule_path !== "string") continue;
|
|
499
|
-
folders.push({ name: repo.name, path: repo.submodule_path });
|
|
500
|
-
}
|
|
501
|
-
return folders;
|
|
502
|
-
}
|
|
503
|
-
function mergeConfig(config, recommendations, root) {
|
|
504
|
-
const servers = Array.isArray(config.servers) ? [...config.servers] : [];
|
|
505
|
-
const next = {
|
|
506
|
-
...config,
|
|
507
|
-
servers,
|
|
508
|
-
workspaceFolders: workspaceFolders(root)
|
|
509
|
-
};
|
|
510
|
-
const existing = new Set(servers.map(serverKey).filter(Boolean));
|
|
511
|
-
const added = [];
|
|
512
|
-
for (const rec of recommendations) {
|
|
513
|
-
if (existing.has(rec.id) || existing.has(rec.command)) continue;
|
|
514
|
-
servers.push({
|
|
515
|
-
id: rec.id,
|
|
516
|
-
command: rec.command,
|
|
517
|
-
args: rec.args,
|
|
518
|
-
extensions: rec.extensions,
|
|
519
|
-
...rec.filenames ? { filenames: rec.filenames } : {},
|
|
520
|
-
...rec.languageIds ? { languageIds: rec.languageIds } : {}
|
|
521
|
-
});
|
|
522
|
-
existing.add(rec.id);
|
|
523
|
-
added.push(rec.id);
|
|
524
|
-
}
|
|
525
|
-
return { config: next, added };
|
|
526
|
-
}
|
|
527
|
-
function runCli() {
|
|
528
|
-
const args = parseArgs(process.argv);
|
|
529
|
-
const config = loadConfig(args.configPath);
|
|
530
|
-
const recommendations = recommend(args.root);
|
|
531
|
-
const existingIds = new Set((config.servers ?? []).map(serverKey).filter(Boolean));
|
|
532
|
-
const missingFromConfig = recommendations.filter(
|
|
533
|
-
(rec) => !existingIds.has(rec.id) && !existingIds.has(rec.command)
|
|
534
|
-
);
|
|
535
|
-
const missingCommands = recommendations.filter((rec) => !rec.available);
|
|
536
|
-
let written = false;
|
|
537
|
-
let added = [];
|
|
538
|
-
if (args.write) {
|
|
539
|
-
const merged = mergeConfig(config, recommendations, args.root);
|
|
540
|
-
saveConfig(args.root, args.config, merged.config);
|
|
541
|
-
written = true;
|
|
542
|
-
added = merged.added;
|
|
543
|
-
}
|
|
544
|
-
const result = {
|
|
545
|
-
root: args.root,
|
|
546
|
-
config: args.config,
|
|
547
|
-
recommended: recommendations,
|
|
548
|
-
missingFromConfig: missingFromConfig.map((rec) => rec.id),
|
|
549
|
-
missingCommands: missingCommands.map((rec) => ({
|
|
550
|
-
id: rec.id,
|
|
551
|
-
command: rec.command,
|
|
552
|
-
availability: rec.availability,
|
|
553
|
-
install: rec.install
|
|
554
|
-
})),
|
|
555
|
-
workspaceFolders: workspaceFolders(args.root),
|
|
556
|
-
written,
|
|
557
|
-
added
|
|
558
|
-
};
|
|
559
|
-
if (args.json) {
|
|
560
|
-
console.log(JSON.stringify(result, null, 2));
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
if (recommendations.length === 0) {
|
|
564
|
-
console.log("No LSP recommendations found from source file extensions.");
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
console.log("Cadre LSP recommendations:");
|
|
568
|
-
for (const rec of recommendations) {
|
|
569
|
-
const status = rec.available ? "available" : "missing";
|
|
570
|
-
const configured = existingIds.has(rec.id) || existingIds.has(rec.command) ? "configured" : "not configured";
|
|
571
|
-
console.log(`- ${rec.label}: ${rec.command} (${status}, ${configured}, ${rec.files} files)`);
|
|
572
|
-
if (!rec.available) console.log(` install: ${rec.install}`);
|
|
573
|
-
}
|
|
574
|
-
if (written) {
|
|
575
|
-
console.log(`Updated ${args.config}; added: ${added.join(", ") || "none"}.`);
|
|
576
|
-
} else if (missingFromConfig.length > 0) {
|
|
577
|
-
console.log("Run with --write to append missing server entries to cadre/lsp.json.");
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
// src/cadre-lsp-setup.ts
|
|
582
|
-
if (["cadre-lsp-setup.js", "cadre-lsp-setup.ts"].includes(import_node_path5.default.basename(process.argv[1] || ""))) {
|
|
583
|
-
try {
|
|
584
|
-
runCli();
|
|
585
|
-
} catch (error) {
|
|
586
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
587
|
-
process.exit(1);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
591
|
-
0 && (module.exports = {
|
|
592
|
-
commandAvailability,
|
|
593
|
-
loadConfig,
|
|
594
|
-
mergeConfig,
|
|
595
|
-
parseArgs,
|
|
596
|
-
recommend,
|
|
597
|
-
runCli,
|
|
598
|
-
scanFiles
|
|
599
|
-
});
|