cadre-ai 2.2.0 → 3.0.1
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 +357 -134
- package/agents/cadre-phase-worker.md +17 -0
- package/agents/cadre-task-worker.md +16 -0
- package/dist/cadre-cli.mjs +2883 -0
- package/dist/cadre-mcp.mjs +33736 -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/gitignore.template +5 -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/wisps/.gitkeep +1 -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
|
@@ -0,0 +1,2883 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// scripts/cli.ts
|
|
4
|
+
import { existsSync as existsSync6, readFileSync as readFileSync6 } from "node:fs";
|
|
5
|
+
import { dirname as dirname6, join as join6, resolve as resolve6 } from "node:path";
|
|
6
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
7
|
+
|
|
8
|
+
// scripts/install.ts
|
|
9
|
+
import { existsSync as existsSync4, mkdtempSync, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync2 } from "node:fs";
|
|
10
|
+
import { homedir as homedir2 } from "node:os";
|
|
11
|
+
import { basename as basename2, dirname as dirname4, join as join4, parse as parse4, resolve as resolve4 } from "node:path";
|
|
12
|
+
|
|
13
|
+
// scripts/cli-options.ts
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { join, resolve } from "node:path";
|
|
16
|
+
|
|
17
|
+
// scripts/native-clients.ts
|
|
18
|
+
import { spawnSync } from "node:child_process";
|
|
19
|
+
var CLIENTS = ["codex", "claude"];
|
|
20
|
+
function commandExists(command) {
|
|
21
|
+
const lookup = process.platform === "win32" ? "where" : "which";
|
|
22
|
+
return spawnSync(lookup, [command], { stdio: "ignore" }).status === 0;
|
|
23
|
+
}
|
|
24
|
+
function runCommand(command, args, capture = false) {
|
|
25
|
+
const result = spawnSync(command, args, {
|
|
26
|
+
encoding: "utf8",
|
|
27
|
+
stdio: capture ? "pipe" : "inherit"
|
|
28
|
+
});
|
|
29
|
+
if (result.error?.code === "ENOENT") {
|
|
30
|
+
throw new Error(`${command} is not installed or not available on PATH`);
|
|
31
|
+
}
|
|
32
|
+
if (result.status !== 0) {
|
|
33
|
+
const detail = capture ? (result.stderr || result.stdout).trim() : "command failed";
|
|
34
|
+
throw new Error(`${command} ${args.join(" ")}: ${detail}`);
|
|
35
|
+
}
|
|
36
|
+
return capture ? result.stdout ?? "" : "";
|
|
37
|
+
}
|
|
38
|
+
function runJson(command, args) {
|
|
39
|
+
const output = runCommand(command, args, true);
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(output);
|
|
42
|
+
} catch {
|
|
43
|
+
throw new Error(`${command} ${args.join(" ")} returned invalid JSON`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// scripts/cli-options.ts
|
|
48
|
+
function parseClient(value) {
|
|
49
|
+
if (value === "all" || value === "auto" || CLIENTS.includes(value)) return value;
|
|
50
|
+
throw new Error("--target/--agent must be auto, all, codex, or claude");
|
|
51
|
+
}
|
|
52
|
+
function defaultMarketplaceRoot() {
|
|
53
|
+
const cadreHome = process.env.CADRE_HOME ? resolve(process.env.CADRE_HOME) : join(homedir(), ".cadre");
|
|
54
|
+
return join(cadreHome, "marketplaces", "cadre");
|
|
55
|
+
}
|
|
56
|
+
function optionValue(args, index, option) {
|
|
57
|
+
const value = args[index + 1];
|
|
58
|
+
if (!value) throw new Error(`${option} requires a value`);
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
function marketplaceFromHome(home) {
|
|
62
|
+
return join(resolve(home), "marketplaces", "cadre");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// scripts/package-plugin.ts
|
|
66
|
+
import { cpSync, existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
67
|
+
import { dirname as dirname2, join as join3, resolve as resolve3 } from "node:path";
|
|
68
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
69
|
+
|
|
70
|
+
// src/domain/templates.ts
|
|
71
|
+
import { createHash } from "node:crypto";
|
|
72
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
73
|
+
import { dirname, extname, join as join2, relative, resolve as resolve2, sep } from "node:path";
|
|
74
|
+
import { fileURLToPath } from "node:url";
|
|
75
|
+
|
|
76
|
+
// src/domain/version.ts
|
|
77
|
+
var CADRE_RUNTIME_VERSION = "3.0.1";
|
|
78
|
+
var TEMPLATE_SET_VERSION = "v1";
|
|
79
|
+
|
|
80
|
+
// src/domain/templates.ts
|
|
81
|
+
var TEMPLATE_IDS = [
|
|
82
|
+
"project/archive-operation",
|
|
83
|
+
"project/gitignore",
|
|
84
|
+
"project/guidelines",
|
|
85
|
+
"project/pattern",
|
|
86
|
+
"project/patterns/index",
|
|
87
|
+
"project/product",
|
|
88
|
+
"project/project",
|
|
89
|
+
"project/refresh",
|
|
90
|
+
"project/refresh-operation",
|
|
91
|
+
"project/styleguides/general",
|
|
92
|
+
"project/styleguides/language",
|
|
93
|
+
"project/tech-stack",
|
|
94
|
+
"project/tracks",
|
|
95
|
+
"project/workflow",
|
|
96
|
+
"styleguide/dart",
|
|
97
|
+
"styleguide/flutter",
|
|
98
|
+
"styleguide/go",
|
|
99
|
+
"styleguide/gradle",
|
|
100
|
+
"styleguide/html-css",
|
|
101
|
+
"styleguide/index",
|
|
102
|
+
"styleguide/java",
|
|
103
|
+
"styleguide/javascript",
|
|
104
|
+
"styleguide/kotlin",
|
|
105
|
+
"styleguide/maven",
|
|
106
|
+
"styleguide/python",
|
|
107
|
+
"styleguide/react",
|
|
108
|
+
"styleguide/swift",
|
|
109
|
+
"styleguide/swiftui",
|
|
110
|
+
"styleguide/typescript",
|
|
111
|
+
"track/bug",
|
|
112
|
+
"track/execution",
|
|
113
|
+
"track/learning",
|
|
114
|
+
"track/plan",
|
|
115
|
+
"track/revert-operation",
|
|
116
|
+
"track/revise-operation",
|
|
117
|
+
"track/revision",
|
|
118
|
+
"track/spec",
|
|
119
|
+
"track/state"
|
|
120
|
+
];
|
|
121
|
+
var catalogCache = null;
|
|
122
|
+
function locateTemplateRoot() {
|
|
123
|
+
const moduleDirectory = dirname(fileURLToPath(import.meta.url));
|
|
124
|
+
const candidates = [
|
|
125
|
+
process.env.CADRE_TEMPLATE_ROOT,
|
|
126
|
+
resolve2(moduleDirectory, "../../templates", TEMPLATE_SET_VERSION),
|
|
127
|
+
resolve2(moduleDirectory, "../templates", TEMPLATE_SET_VERSION)
|
|
128
|
+
].filter((candidate) => Boolean(candidate));
|
|
129
|
+
const found = candidates.find((candidate) => existsSync(candidate));
|
|
130
|
+
if (!found) throw new Error(`Cadre template set ${TEMPLATE_SET_VERSION} is unavailable`);
|
|
131
|
+
return found;
|
|
132
|
+
}
|
|
133
|
+
function walk(root, directory = root) {
|
|
134
|
+
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
135
|
+
const path = join2(directory, entry.name);
|
|
136
|
+
return entry.isDirectory() ? walk(root, path) : [relative(root, path).split(sep).join("/")];
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function templateId(path) {
|
|
140
|
+
if (path.endsWith("/.gitkeep")) return null;
|
|
141
|
+
if (path === "init/gitignore.template") return "project/gitignore";
|
|
142
|
+
const withoutExtension = path.slice(0, -extname(path).length);
|
|
143
|
+
const styleguidePrefix = "styleguides/";
|
|
144
|
+
if (path.startsWith(styleguidePrefix)) return `styleguide/${withoutExtension.slice(styleguidePrefix.length)}`;
|
|
145
|
+
if (path.startsWith("init/")) return `project/${withoutExtension.slice("init/".length)}`;
|
|
146
|
+
return withoutExtension;
|
|
147
|
+
}
|
|
148
|
+
function mimeType(path) {
|
|
149
|
+
if (path === "init/gitignore.template") return "text/plain";
|
|
150
|
+
return path.endsWith(".json") ? "application/json" : "text/markdown";
|
|
151
|
+
}
|
|
152
|
+
function assertCompleteCatalog(catalog) {
|
|
153
|
+
const actual = new Set(catalog.map((template) => template.id));
|
|
154
|
+
if (actual.size !== catalog.length) throw new Error(`Cadre template set ${TEMPLATE_SET_VERSION} has duplicate identifiers`);
|
|
155
|
+
const expected = new Set(TEMPLATE_IDS);
|
|
156
|
+
const missing = TEMPLATE_IDS.filter((id) => !actual.has(id));
|
|
157
|
+
const unexpected = [...actual].filter((id) => !expected.has(id)).sort();
|
|
158
|
+
if (missing.length || unexpected.length) {
|
|
159
|
+
const details = [
|
|
160
|
+
missing.length ? `missing ${missing.join(", ")}` : "",
|
|
161
|
+
unexpected.length ? `unexpected ${unexpected.join(", ")}` : ""
|
|
162
|
+
].filter(Boolean).join("; ");
|
|
163
|
+
throw new Error(`Cadre template set ${TEMPLATE_SET_VERSION} is incomplete: ${details}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function templateCatalog() {
|
|
167
|
+
if (!catalogCache) {
|
|
168
|
+
const root = locateTemplateRoot();
|
|
169
|
+
const catalog = walk(root).map((relativePath) => {
|
|
170
|
+
const id = templateId(relativePath);
|
|
171
|
+
if (!id) return null;
|
|
172
|
+
const content = readFileSync(join2(root, relativePath), "utf8");
|
|
173
|
+
return {
|
|
174
|
+
id,
|
|
175
|
+
uri: `cadre://templates/${TEMPLATE_SET_VERSION}/${id}`,
|
|
176
|
+
relativePath,
|
|
177
|
+
mimeType: mimeType(relativePath),
|
|
178
|
+
content,
|
|
179
|
+
sha256: createHash("sha256").update(content).digest("hex")
|
|
180
|
+
};
|
|
181
|
+
}).filter((entry) => entry !== null).sort((left, right) => left.id.localeCompare(right.id));
|
|
182
|
+
assertCompleteCatalog(catalog);
|
|
183
|
+
catalogCache = catalog;
|
|
184
|
+
}
|
|
185
|
+
return catalogCache.map((template) => ({ ...template }));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// scripts/package-plugin.ts
|
|
189
|
+
var sourceRoot = resolve3(dirname2(fileURLToPath2(import.meta.url)), "..");
|
|
190
|
+
var requiredEntries = [
|
|
191
|
+
"skills",
|
|
192
|
+
"templates",
|
|
193
|
+
"dist/cadre-mcp.mjs",
|
|
194
|
+
".mcp.json",
|
|
195
|
+
".mcp.codex.json",
|
|
196
|
+
"LICENSE",
|
|
197
|
+
"README.md"
|
|
198
|
+
];
|
|
199
|
+
var optionalEntries = ["hooks", "hooks.json", ".app.json", "assets", "commands", "agents"];
|
|
200
|
+
function readJson(path) {
|
|
201
|
+
return JSON.parse(readFileSync2(path, "utf8"));
|
|
202
|
+
}
|
|
203
|
+
function writeJson(path, value) {
|
|
204
|
+
mkdirSync(dirname2(path), { recursive: true });
|
|
205
|
+
writeFileSync(path, `${JSON.stringify(value, null, 2)}
|
|
206
|
+
`);
|
|
207
|
+
}
|
|
208
|
+
function withCachebuster(version, product, cachebuster) {
|
|
209
|
+
const base = version.split("+", 1)[0];
|
|
210
|
+
return `${base}+${product}.${cachebuster}`;
|
|
211
|
+
}
|
|
212
|
+
function defaultCachebuster() {
|
|
213
|
+
return `local-${(/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").replace(/\.\d{3}Z$/, "Z")}`;
|
|
214
|
+
}
|
|
215
|
+
function packagePluginMarketplace(outputRoot, requestedCachebuster = defaultCachebuster()) {
|
|
216
|
+
templateCatalog();
|
|
217
|
+
const targetRoot = resolve3(outputRoot);
|
|
218
|
+
const cachebuster = requestedCachebuster.trim();
|
|
219
|
+
if (!/^[0-9A-Za-z-]+$/.test(cachebuster)) {
|
|
220
|
+
throw new Error("cachebuster must contain only letters, digits, and hyphens");
|
|
221
|
+
}
|
|
222
|
+
const pluginRoot = join3(targetRoot, "plugins", "cadre");
|
|
223
|
+
if (existsSync2(pluginRoot)) throw new Error(`plugin output already exists: ${pluginRoot}`);
|
|
224
|
+
mkdirSync(pluginRoot, { recursive: true });
|
|
225
|
+
for (const entry of requiredEntries) {
|
|
226
|
+
const source = join3(sourceRoot, entry);
|
|
227
|
+
if (!existsSync2(source)) throw new Error(`required plugin entry is missing: ${entry}`);
|
|
228
|
+
cpSync(source, join3(pluginRoot, entry), { recursive: true });
|
|
229
|
+
}
|
|
230
|
+
for (const entry of optionalEntries) {
|
|
231
|
+
const source = join3(sourceRoot, entry);
|
|
232
|
+
if (existsSync2(source)) cpSync(source, join3(pluginRoot, entry), { recursive: true });
|
|
233
|
+
}
|
|
234
|
+
const codexManifest = readJson(join3(sourceRoot, ".codex-plugin", "plugin.json"));
|
|
235
|
+
codexManifest.version = withCachebuster(codexManifest.version, "codex", cachebuster);
|
|
236
|
+
writeJson(join3(pluginRoot, ".codex-plugin", "plugin.json"), codexManifest);
|
|
237
|
+
const claudeManifest = readJson(join3(sourceRoot, ".claude-plugin", "plugin.json"));
|
|
238
|
+
claudeManifest.version = withCachebuster(claudeManifest.version, "claude", cachebuster);
|
|
239
|
+
writeJson(join3(pluginRoot, ".claude-plugin", "plugin.json"), claudeManifest);
|
|
240
|
+
writeJson(
|
|
241
|
+
join3(targetRoot, ".agents", "plugins", "marketplace.json"),
|
|
242
|
+
readJson(join3(sourceRoot, "marketplace", "codex.json"))
|
|
243
|
+
);
|
|
244
|
+
writeJson(
|
|
245
|
+
join3(targetRoot, ".claude-plugin", "marketplace.json"),
|
|
246
|
+
readJson(join3(sourceRoot, "marketplace", "claude.json"))
|
|
247
|
+
);
|
|
248
|
+
return { targetRoot, pluginRoot, cachebuster };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// ../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
252
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
253
|
+
const len = text.length;
|
|
254
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
255
|
+
function scanHexDigits(count, exact) {
|
|
256
|
+
let digits = 0;
|
|
257
|
+
let value2 = 0;
|
|
258
|
+
while (digits < count || !exact) {
|
|
259
|
+
let ch = text.charCodeAt(pos);
|
|
260
|
+
if (ch >= 48 && ch <= 57) {
|
|
261
|
+
value2 = value2 * 16 + ch - 48;
|
|
262
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
263
|
+
value2 = value2 * 16 + ch - 65 + 10;
|
|
264
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
265
|
+
value2 = value2 * 16 + ch - 97 + 10;
|
|
266
|
+
} else {
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
pos++;
|
|
270
|
+
digits++;
|
|
271
|
+
}
|
|
272
|
+
if (digits < count) {
|
|
273
|
+
value2 = -1;
|
|
274
|
+
}
|
|
275
|
+
return value2;
|
|
276
|
+
}
|
|
277
|
+
function setPosition(newPosition) {
|
|
278
|
+
pos = newPosition;
|
|
279
|
+
value = "";
|
|
280
|
+
tokenOffset = 0;
|
|
281
|
+
token = 16;
|
|
282
|
+
scanError = 0;
|
|
283
|
+
}
|
|
284
|
+
function scanNumber() {
|
|
285
|
+
let start = pos;
|
|
286
|
+
if (text.charCodeAt(pos) === 48) {
|
|
287
|
+
pos++;
|
|
288
|
+
} else {
|
|
289
|
+
pos++;
|
|
290
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
291
|
+
pos++;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
295
|
+
pos++;
|
|
296
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
297
|
+
pos++;
|
|
298
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
299
|
+
pos++;
|
|
300
|
+
}
|
|
301
|
+
} else {
|
|
302
|
+
scanError = 3;
|
|
303
|
+
return text.substring(start, pos);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
let end = pos;
|
|
307
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
308
|
+
pos++;
|
|
309
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
310
|
+
pos++;
|
|
311
|
+
}
|
|
312
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
313
|
+
pos++;
|
|
314
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
315
|
+
pos++;
|
|
316
|
+
}
|
|
317
|
+
end = pos;
|
|
318
|
+
} else {
|
|
319
|
+
scanError = 3;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return text.substring(start, end);
|
|
323
|
+
}
|
|
324
|
+
function scanString() {
|
|
325
|
+
let result = "", start = pos;
|
|
326
|
+
while (true) {
|
|
327
|
+
if (pos >= len) {
|
|
328
|
+
result += text.substring(start, pos);
|
|
329
|
+
scanError = 2;
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
const ch = text.charCodeAt(pos);
|
|
333
|
+
if (ch === 34) {
|
|
334
|
+
result += text.substring(start, pos);
|
|
335
|
+
pos++;
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
if (ch === 92) {
|
|
339
|
+
result += text.substring(start, pos);
|
|
340
|
+
pos++;
|
|
341
|
+
if (pos >= len) {
|
|
342
|
+
scanError = 2;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
const ch2 = text.charCodeAt(pos++);
|
|
346
|
+
switch (ch2) {
|
|
347
|
+
case 34:
|
|
348
|
+
result += '"';
|
|
349
|
+
break;
|
|
350
|
+
case 92:
|
|
351
|
+
result += "\\";
|
|
352
|
+
break;
|
|
353
|
+
case 47:
|
|
354
|
+
result += "/";
|
|
355
|
+
break;
|
|
356
|
+
case 98:
|
|
357
|
+
result += "\b";
|
|
358
|
+
break;
|
|
359
|
+
case 102:
|
|
360
|
+
result += "\f";
|
|
361
|
+
break;
|
|
362
|
+
case 110:
|
|
363
|
+
result += "\n";
|
|
364
|
+
break;
|
|
365
|
+
case 114:
|
|
366
|
+
result += "\r";
|
|
367
|
+
break;
|
|
368
|
+
case 116:
|
|
369
|
+
result += " ";
|
|
370
|
+
break;
|
|
371
|
+
case 117:
|
|
372
|
+
const ch3 = scanHexDigits(4, true);
|
|
373
|
+
if (ch3 >= 0) {
|
|
374
|
+
result += String.fromCharCode(ch3);
|
|
375
|
+
} else {
|
|
376
|
+
scanError = 4;
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
default:
|
|
380
|
+
scanError = 5;
|
|
381
|
+
}
|
|
382
|
+
start = pos;
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (ch >= 0 && ch <= 31) {
|
|
386
|
+
if (isLineBreak(ch)) {
|
|
387
|
+
result += text.substring(start, pos);
|
|
388
|
+
scanError = 2;
|
|
389
|
+
break;
|
|
390
|
+
} else {
|
|
391
|
+
scanError = 6;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
pos++;
|
|
395
|
+
}
|
|
396
|
+
return result;
|
|
397
|
+
}
|
|
398
|
+
function scanNext() {
|
|
399
|
+
value = "";
|
|
400
|
+
scanError = 0;
|
|
401
|
+
tokenOffset = pos;
|
|
402
|
+
lineStartOffset = lineNumber;
|
|
403
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
404
|
+
if (pos >= len) {
|
|
405
|
+
tokenOffset = len;
|
|
406
|
+
return token = 17;
|
|
407
|
+
}
|
|
408
|
+
let code = text.charCodeAt(pos);
|
|
409
|
+
if (isWhiteSpace(code)) {
|
|
410
|
+
do {
|
|
411
|
+
pos++;
|
|
412
|
+
value += String.fromCharCode(code);
|
|
413
|
+
code = text.charCodeAt(pos);
|
|
414
|
+
} while (isWhiteSpace(code));
|
|
415
|
+
return token = 15;
|
|
416
|
+
}
|
|
417
|
+
if (isLineBreak(code)) {
|
|
418
|
+
pos++;
|
|
419
|
+
value += String.fromCharCode(code);
|
|
420
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
421
|
+
pos++;
|
|
422
|
+
value += "\n";
|
|
423
|
+
}
|
|
424
|
+
lineNumber++;
|
|
425
|
+
tokenLineStartOffset = pos;
|
|
426
|
+
return token = 14;
|
|
427
|
+
}
|
|
428
|
+
switch (code) {
|
|
429
|
+
// tokens: []{}:,
|
|
430
|
+
case 123:
|
|
431
|
+
pos++;
|
|
432
|
+
return token = 1;
|
|
433
|
+
case 125:
|
|
434
|
+
pos++;
|
|
435
|
+
return token = 2;
|
|
436
|
+
case 91:
|
|
437
|
+
pos++;
|
|
438
|
+
return token = 3;
|
|
439
|
+
case 93:
|
|
440
|
+
pos++;
|
|
441
|
+
return token = 4;
|
|
442
|
+
case 58:
|
|
443
|
+
pos++;
|
|
444
|
+
return token = 6;
|
|
445
|
+
case 44:
|
|
446
|
+
pos++;
|
|
447
|
+
return token = 5;
|
|
448
|
+
// strings
|
|
449
|
+
case 34:
|
|
450
|
+
pos++;
|
|
451
|
+
value = scanString();
|
|
452
|
+
return token = 10;
|
|
453
|
+
// comments
|
|
454
|
+
case 47:
|
|
455
|
+
const start = pos - 1;
|
|
456
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
457
|
+
pos += 2;
|
|
458
|
+
while (pos < len) {
|
|
459
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
pos++;
|
|
463
|
+
}
|
|
464
|
+
value = text.substring(start, pos);
|
|
465
|
+
return token = 12;
|
|
466
|
+
}
|
|
467
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
468
|
+
pos += 2;
|
|
469
|
+
const safeLength = len - 1;
|
|
470
|
+
let commentClosed = false;
|
|
471
|
+
while (pos < safeLength) {
|
|
472
|
+
const ch = text.charCodeAt(pos);
|
|
473
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
474
|
+
pos += 2;
|
|
475
|
+
commentClosed = true;
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
pos++;
|
|
479
|
+
if (isLineBreak(ch)) {
|
|
480
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
481
|
+
pos++;
|
|
482
|
+
}
|
|
483
|
+
lineNumber++;
|
|
484
|
+
tokenLineStartOffset = pos;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (!commentClosed) {
|
|
488
|
+
pos++;
|
|
489
|
+
scanError = 1;
|
|
490
|
+
}
|
|
491
|
+
value = text.substring(start, pos);
|
|
492
|
+
return token = 13;
|
|
493
|
+
}
|
|
494
|
+
value += String.fromCharCode(code);
|
|
495
|
+
pos++;
|
|
496
|
+
return token = 16;
|
|
497
|
+
// numbers
|
|
498
|
+
case 45:
|
|
499
|
+
value += String.fromCharCode(code);
|
|
500
|
+
pos++;
|
|
501
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
502
|
+
return token = 16;
|
|
503
|
+
}
|
|
504
|
+
// found a minus, followed by a number so
|
|
505
|
+
// we fall through to proceed with scanning
|
|
506
|
+
// numbers
|
|
507
|
+
case 48:
|
|
508
|
+
case 49:
|
|
509
|
+
case 50:
|
|
510
|
+
case 51:
|
|
511
|
+
case 52:
|
|
512
|
+
case 53:
|
|
513
|
+
case 54:
|
|
514
|
+
case 55:
|
|
515
|
+
case 56:
|
|
516
|
+
case 57:
|
|
517
|
+
value += scanNumber();
|
|
518
|
+
return token = 11;
|
|
519
|
+
// literals and unknown symbols
|
|
520
|
+
default:
|
|
521
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
522
|
+
pos++;
|
|
523
|
+
code = text.charCodeAt(pos);
|
|
524
|
+
}
|
|
525
|
+
if (tokenOffset !== pos) {
|
|
526
|
+
value = text.substring(tokenOffset, pos);
|
|
527
|
+
switch (value) {
|
|
528
|
+
case "true":
|
|
529
|
+
return token = 8;
|
|
530
|
+
case "false":
|
|
531
|
+
return token = 9;
|
|
532
|
+
case "null":
|
|
533
|
+
return token = 7;
|
|
534
|
+
}
|
|
535
|
+
return token = 16;
|
|
536
|
+
}
|
|
537
|
+
value += String.fromCharCode(code);
|
|
538
|
+
pos++;
|
|
539
|
+
return token = 16;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
function isUnknownContentCharacter(code) {
|
|
543
|
+
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
switch (code) {
|
|
547
|
+
case 125:
|
|
548
|
+
case 93:
|
|
549
|
+
case 123:
|
|
550
|
+
case 91:
|
|
551
|
+
case 34:
|
|
552
|
+
case 58:
|
|
553
|
+
case 44:
|
|
554
|
+
case 47:
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
function scanNextNonTrivia() {
|
|
560
|
+
let result;
|
|
561
|
+
do {
|
|
562
|
+
result = scanNext();
|
|
563
|
+
} while (result >= 12 && result <= 15);
|
|
564
|
+
return result;
|
|
565
|
+
}
|
|
566
|
+
return {
|
|
567
|
+
setPosition,
|
|
568
|
+
getPosition: () => pos,
|
|
569
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
570
|
+
getToken: () => token,
|
|
571
|
+
getTokenValue: () => value,
|
|
572
|
+
getTokenOffset: () => tokenOffset,
|
|
573
|
+
getTokenLength: () => pos - tokenOffset,
|
|
574
|
+
getTokenStartLine: () => lineStartOffset,
|
|
575
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
576
|
+
getTokenError: () => scanError
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
function isWhiteSpace(ch) {
|
|
580
|
+
return ch === 32 || ch === 9;
|
|
581
|
+
}
|
|
582
|
+
function isLineBreak(ch) {
|
|
583
|
+
return ch === 10 || ch === 13;
|
|
584
|
+
}
|
|
585
|
+
function isDigit(ch) {
|
|
586
|
+
return ch >= 48 && ch <= 57;
|
|
587
|
+
}
|
|
588
|
+
var CharacterCodes;
|
|
589
|
+
(function(CharacterCodes2) {
|
|
590
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
591
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
592
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
593
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
594
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
595
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
596
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
597
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
598
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
599
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
600
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
601
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
602
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
603
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
604
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
605
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
606
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
607
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
608
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
609
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
610
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
611
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
612
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
613
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
614
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
615
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
616
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
617
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
618
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
619
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
620
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
621
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
622
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
623
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
624
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
625
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
626
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
627
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
628
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
629
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
630
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
631
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
632
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
633
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
634
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
635
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
636
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
637
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
638
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
639
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
640
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
641
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
642
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
643
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
644
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
645
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
646
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
647
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
648
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
649
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
650
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
651
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
652
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
653
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
654
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
655
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
656
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
657
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
658
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
659
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
660
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
661
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
662
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
663
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
664
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
665
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
666
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
667
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
668
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
669
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
670
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
671
|
+
|
|
672
|
+
// ../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
673
|
+
var cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
674
|
+
return " ".repeat(index);
|
|
675
|
+
});
|
|
676
|
+
var maxCachedValues = 200;
|
|
677
|
+
var cachedBreakLinesWithSpaces = {
|
|
678
|
+
" ": {
|
|
679
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
680
|
+
return "\n" + " ".repeat(index);
|
|
681
|
+
}),
|
|
682
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
683
|
+
return "\r" + " ".repeat(index);
|
|
684
|
+
}),
|
|
685
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
686
|
+
return "\r\n" + " ".repeat(index);
|
|
687
|
+
})
|
|
688
|
+
},
|
|
689
|
+
" ": {
|
|
690
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
691
|
+
return "\n" + " ".repeat(index);
|
|
692
|
+
}),
|
|
693
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
694
|
+
return "\r" + " ".repeat(index);
|
|
695
|
+
}),
|
|
696
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
697
|
+
return "\r\n" + " ".repeat(index);
|
|
698
|
+
})
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
var supportedEols = ["\n", "\r", "\r\n"];
|
|
702
|
+
|
|
703
|
+
// ../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/format.js
|
|
704
|
+
function format(documentText, range, options) {
|
|
705
|
+
let initialIndentLevel;
|
|
706
|
+
let formatText;
|
|
707
|
+
let formatTextStart;
|
|
708
|
+
let rangeStart;
|
|
709
|
+
let rangeEnd;
|
|
710
|
+
if (range) {
|
|
711
|
+
rangeStart = range.offset;
|
|
712
|
+
rangeEnd = rangeStart + range.length;
|
|
713
|
+
formatTextStart = rangeStart;
|
|
714
|
+
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
|
|
715
|
+
formatTextStart--;
|
|
716
|
+
}
|
|
717
|
+
let endOffset = rangeEnd;
|
|
718
|
+
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
|
|
719
|
+
endOffset++;
|
|
720
|
+
}
|
|
721
|
+
formatText = documentText.substring(formatTextStart, endOffset);
|
|
722
|
+
initialIndentLevel = computeIndentLevel(formatText, options);
|
|
723
|
+
} else {
|
|
724
|
+
formatText = documentText;
|
|
725
|
+
initialIndentLevel = 0;
|
|
726
|
+
formatTextStart = 0;
|
|
727
|
+
rangeStart = 0;
|
|
728
|
+
rangeEnd = documentText.length;
|
|
729
|
+
}
|
|
730
|
+
const eol = getEOL(options, documentText);
|
|
731
|
+
const eolFastPathSupported = supportedEols.includes(eol);
|
|
732
|
+
let numberLineBreaks = 0;
|
|
733
|
+
let indentLevel = 0;
|
|
734
|
+
let indentValue;
|
|
735
|
+
if (options.insertSpaces) {
|
|
736
|
+
indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
|
|
737
|
+
} else {
|
|
738
|
+
indentValue = " ";
|
|
739
|
+
}
|
|
740
|
+
const indentType = indentValue === " " ? " " : " ";
|
|
741
|
+
let scanner = createScanner(formatText, false);
|
|
742
|
+
let hasError = false;
|
|
743
|
+
function newLinesAndIndent() {
|
|
744
|
+
if (numberLineBreaks > 1) {
|
|
745
|
+
return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
746
|
+
}
|
|
747
|
+
const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
|
|
748
|
+
if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
|
|
749
|
+
return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
750
|
+
}
|
|
751
|
+
if (amountOfSpaces <= 0) {
|
|
752
|
+
return eol;
|
|
753
|
+
}
|
|
754
|
+
return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
|
|
755
|
+
}
|
|
756
|
+
function scanNext() {
|
|
757
|
+
let token = scanner.scan();
|
|
758
|
+
numberLineBreaks = 0;
|
|
759
|
+
while (token === 15 || token === 14) {
|
|
760
|
+
if (token === 14 && options.keepLines) {
|
|
761
|
+
numberLineBreaks += 1;
|
|
762
|
+
} else if (token === 14) {
|
|
763
|
+
numberLineBreaks = 1;
|
|
764
|
+
}
|
|
765
|
+
token = scanner.scan();
|
|
766
|
+
}
|
|
767
|
+
hasError = token === 16 || scanner.getTokenError() !== 0;
|
|
768
|
+
return token;
|
|
769
|
+
}
|
|
770
|
+
const editOperations = [];
|
|
771
|
+
function addEdit(text, startOffset, endOffset) {
|
|
772
|
+
if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) {
|
|
773
|
+
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
let firstToken = scanNext();
|
|
777
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
778
|
+
addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
779
|
+
}
|
|
780
|
+
if (firstToken !== 17) {
|
|
781
|
+
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
782
|
+
let initialIndent = indentValue.length * initialIndentLevel < 20 && options.insertSpaces ? cachedSpaces[indentValue.length * initialIndentLevel] : repeat(indentValue, initialIndentLevel);
|
|
783
|
+
addEdit(initialIndent, formatTextStart, firstTokenStart);
|
|
784
|
+
}
|
|
785
|
+
while (firstToken !== 17) {
|
|
786
|
+
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
787
|
+
let secondToken = scanNext();
|
|
788
|
+
let replaceContent = "";
|
|
789
|
+
let needsLineBreak = false;
|
|
790
|
+
while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
|
|
791
|
+
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
792
|
+
addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
|
|
793
|
+
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
794
|
+
needsLineBreak = secondToken === 12;
|
|
795
|
+
replaceContent = needsLineBreak ? newLinesAndIndent() : "";
|
|
796
|
+
secondToken = scanNext();
|
|
797
|
+
}
|
|
798
|
+
if (secondToken === 2) {
|
|
799
|
+
if (firstToken !== 1) {
|
|
800
|
+
indentLevel--;
|
|
801
|
+
}
|
|
802
|
+
;
|
|
803
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) {
|
|
804
|
+
replaceContent = newLinesAndIndent();
|
|
805
|
+
} else if (options.keepLines) {
|
|
806
|
+
replaceContent = cachedSpaces[1];
|
|
807
|
+
}
|
|
808
|
+
} else if (secondToken === 4) {
|
|
809
|
+
if (firstToken !== 3) {
|
|
810
|
+
indentLevel--;
|
|
811
|
+
}
|
|
812
|
+
;
|
|
813
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) {
|
|
814
|
+
replaceContent = newLinesAndIndent();
|
|
815
|
+
} else if (options.keepLines) {
|
|
816
|
+
replaceContent = cachedSpaces[1];
|
|
817
|
+
}
|
|
818
|
+
} else {
|
|
819
|
+
switch (firstToken) {
|
|
820
|
+
case 3:
|
|
821
|
+
case 1:
|
|
822
|
+
indentLevel++;
|
|
823
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
824
|
+
replaceContent = newLinesAndIndent();
|
|
825
|
+
} else {
|
|
826
|
+
replaceContent = cachedSpaces[1];
|
|
827
|
+
}
|
|
828
|
+
break;
|
|
829
|
+
case 5:
|
|
830
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
831
|
+
replaceContent = newLinesAndIndent();
|
|
832
|
+
} else {
|
|
833
|
+
replaceContent = cachedSpaces[1];
|
|
834
|
+
}
|
|
835
|
+
break;
|
|
836
|
+
case 12:
|
|
837
|
+
replaceContent = newLinesAndIndent();
|
|
838
|
+
break;
|
|
839
|
+
case 13:
|
|
840
|
+
if (numberLineBreaks > 0) {
|
|
841
|
+
replaceContent = newLinesAndIndent();
|
|
842
|
+
} else if (!needsLineBreak) {
|
|
843
|
+
replaceContent = cachedSpaces[1];
|
|
844
|
+
}
|
|
845
|
+
break;
|
|
846
|
+
case 6:
|
|
847
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
848
|
+
replaceContent = newLinesAndIndent();
|
|
849
|
+
} else if (!needsLineBreak) {
|
|
850
|
+
replaceContent = cachedSpaces[1];
|
|
851
|
+
}
|
|
852
|
+
break;
|
|
853
|
+
case 10:
|
|
854
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
855
|
+
replaceContent = newLinesAndIndent();
|
|
856
|
+
} else if (secondToken === 6 && !needsLineBreak) {
|
|
857
|
+
replaceContent = "";
|
|
858
|
+
}
|
|
859
|
+
break;
|
|
860
|
+
case 7:
|
|
861
|
+
case 8:
|
|
862
|
+
case 9:
|
|
863
|
+
case 11:
|
|
864
|
+
case 2:
|
|
865
|
+
case 4:
|
|
866
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
867
|
+
replaceContent = newLinesAndIndent();
|
|
868
|
+
} else {
|
|
869
|
+
if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) {
|
|
870
|
+
replaceContent = cachedSpaces[1];
|
|
871
|
+
} else if (secondToken !== 5 && secondToken !== 17) {
|
|
872
|
+
hasError = true;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
break;
|
|
876
|
+
case 16:
|
|
877
|
+
hasError = true;
|
|
878
|
+
break;
|
|
879
|
+
}
|
|
880
|
+
if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) {
|
|
881
|
+
replaceContent = newLinesAndIndent();
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
if (secondToken === 17) {
|
|
885
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
886
|
+
replaceContent = newLinesAndIndent();
|
|
887
|
+
} else {
|
|
888
|
+
replaceContent = options.insertFinalNewline ? eol : "";
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
892
|
+
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
893
|
+
firstToken = secondToken;
|
|
894
|
+
}
|
|
895
|
+
return editOperations;
|
|
896
|
+
}
|
|
897
|
+
function repeat(s, count) {
|
|
898
|
+
let result = "";
|
|
899
|
+
for (let i = 0; i < count; i++) {
|
|
900
|
+
result += s;
|
|
901
|
+
}
|
|
902
|
+
return result;
|
|
903
|
+
}
|
|
904
|
+
function computeIndentLevel(content, options) {
|
|
905
|
+
let i = 0;
|
|
906
|
+
let nChars = 0;
|
|
907
|
+
const tabSize = options.tabSize || 4;
|
|
908
|
+
while (i < content.length) {
|
|
909
|
+
let ch = content.charAt(i);
|
|
910
|
+
if (ch === cachedSpaces[1]) {
|
|
911
|
+
nChars++;
|
|
912
|
+
} else if (ch === " ") {
|
|
913
|
+
nChars += tabSize;
|
|
914
|
+
} else {
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
i++;
|
|
918
|
+
}
|
|
919
|
+
return Math.floor(nChars / tabSize);
|
|
920
|
+
}
|
|
921
|
+
function getEOL(options, text) {
|
|
922
|
+
for (let i = 0; i < text.length; i++) {
|
|
923
|
+
const ch = text.charAt(i);
|
|
924
|
+
if (ch === "\r") {
|
|
925
|
+
if (i + 1 < text.length && text.charAt(i + 1) === "\n") {
|
|
926
|
+
return "\r\n";
|
|
927
|
+
}
|
|
928
|
+
return "\r";
|
|
929
|
+
} else if (ch === "\n") {
|
|
930
|
+
return "\n";
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
return options && options.eol || "\n";
|
|
934
|
+
}
|
|
935
|
+
function isEOL(text, offset) {
|
|
936
|
+
return "\r\n".indexOf(text.charAt(offset)) !== -1;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// ../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
940
|
+
var ParseOptions;
|
|
941
|
+
(function(ParseOptions2) {
|
|
942
|
+
ParseOptions2.DEFAULT = {
|
|
943
|
+
allowTrailingComma: false
|
|
944
|
+
};
|
|
945
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
946
|
+
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
947
|
+
let currentProperty = null;
|
|
948
|
+
let currentParent = [];
|
|
949
|
+
const previousParents = [];
|
|
950
|
+
function onValue(value) {
|
|
951
|
+
if (Array.isArray(currentParent)) {
|
|
952
|
+
currentParent.push(value);
|
|
953
|
+
} else if (currentProperty !== null) {
|
|
954
|
+
currentParent[currentProperty] = value;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
const visitor = {
|
|
958
|
+
onObjectBegin: () => {
|
|
959
|
+
const object = {};
|
|
960
|
+
onValue(object);
|
|
961
|
+
previousParents.push(currentParent);
|
|
962
|
+
currentParent = object;
|
|
963
|
+
currentProperty = null;
|
|
964
|
+
},
|
|
965
|
+
onObjectProperty: (name) => {
|
|
966
|
+
currentProperty = name;
|
|
967
|
+
},
|
|
968
|
+
onObjectEnd: () => {
|
|
969
|
+
currentParent = previousParents.pop();
|
|
970
|
+
},
|
|
971
|
+
onArrayBegin: () => {
|
|
972
|
+
const array = [];
|
|
973
|
+
onValue(array);
|
|
974
|
+
previousParents.push(currentParent);
|
|
975
|
+
currentParent = array;
|
|
976
|
+
currentProperty = null;
|
|
977
|
+
},
|
|
978
|
+
onArrayEnd: () => {
|
|
979
|
+
currentParent = previousParents.pop();
|
|
980
|
+
},
|
|
981
|
+
onLiteralValue: onValue,
|
|
982
|
+
onError: (error, offset, length) => {
|
|
983
|
+
errors.push({ error, offset, length });
|
|
984
|
+
}
|
|
985
|
+
};
|
|
986
|
+
visit(text, visitor, options);
|
|
987
|
+
return currentParent[0];
|
|
988
|
+
}
|
|
989
|
+
function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
990
|
+
let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: void 0 };
|
|
991
|
+
function ensurePropertyComplete(endOffset) {
|
|
992
|
+
if (currentParent.type === "property") {
|
|
993
|
+
currentParent.length = endOffset - currentParent.offset;
|
|
994
|
+
currentParent = currentParent.parent;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
function onValue(valueNode) {
|
|
998
|
+
currentParent.children.push(valueNode);
|
|
999
|
+
return valueNode;
|
|
1000
|
+
}
|
|
1001
|
+
const visitor = {
|
|
1002
|
+
onObjectBegin: (offset) => {
|
|
1003
|
+
currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
|
|
1004
|
+
},
|
|
1005
|
+
onObjectProperty: (name, offset, length) => {
|
|
1006
|
+
currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
|
|
1007
|
+
currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
|
|
1008
|
+
},
|
|
1009
|
+
onObjectEnd: (offset, length) => {
|
|
1010
|
+
ensurePropertyComplete(offset + length);
|
|
1011
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
1012
|
+
currentParent = currentParent.parent;
|
|
1013
|
+
ensurePropertyComplete(offset + length);
|
|
1014
|
+
},
|
|
1015
|
+
onArrayBegin: (offset, length) => {
|
|
1016
|
+
currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
|
|
1017
|
+
},
|
|
1018
|
+
onArrayEnd: (offset, length) => {
|
|
1019
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
1020
|
+
currentParent = currentParent.parent;
|
|
1021
|
+
ensurePropertyComplete(offset + length);
|
|
1022
|
+
},
|
|
1023
|
+
onLiteralValue: (value, offset, length) => {
|
|
1024
|
+
onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
|
|
1025
|
+
ensurePropertyComplete(offset + length);
|
|
1026
|
+
},
|
|
1027
|
+
onSeparator: (sep2, offset, length) => {
|
|
1028
|
+
if (currentParent.type === "property") {
|
|
1029
|
+
if (sep2 === ":") {
|
|
1030
|
+
currentParent.colonOffset = offset;
|
|
1031
|
+
} else if (sep2 === ",") {
|
|
1032
|
+
ensurePropertyComplete(offset);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
},
|
|
1036
|
+
onError: (error, offset, length) => {
|
|
1037
|
+
errors.push({ error, offset, length });
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
visit(text, visitor, options);
|
|
1041
|
+
const result = currentParent.children[0];
|
|
1042
|
+
if (result) {
|
|
1043
|
+
delete result.parent;
|
|
1044
|
+
}
|
|
1045
|
+
return result;
|
|
1046
|
+
}
|
|
1047
|
+
function findNodeAtLocation(root, path) {
|
|
1048
|
+
if (!root) {
|
|
1049
|
+
return void 0;
|
|
1050
|
+
}
|
|
1051
|
+
let node = root;
|
|
1052
|
+
for (let segment of path) {
|
|
1053
|
+
if (typeof segment === "string") {
|
|
1054
|
+
if (node.type !== "object" || !Array.isArray(node.children)) {
|
|
1055
|
+
return void 0;
|
|
1056
|
+
}
|
|
1057
|
+
let found = false;
|
|
1058
|
+
for (const propertyNode of node.children) {
|
|
1059
|
+
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
|
|
1060
|
+
node = propertyNode.children[1];
|
|
1061
|
+
found = true;
|
|
1062
|
+
break;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
if (!found) {
|
|
1066
|
+
return void 0;
|
|
1067
|
+
}
|
|
1068
|
+
} else {
|
|
1069
|
+
const index = segment;
|
|
1070
|
+
if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
|
|
1071
|
+
return void 0;
|
|
1072
|
+
}
|
|
1073
|
+
node = node.children[index];
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return node;
|
|
1077
|
+
}
|
|
1078
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
1079
|
+
const _scanner = createScanner(text, false);
|
|
1080
|
+
const _jsonPath = [];
|
|
1081
|
+
let suppressedCallbacks = 0;
|
|
1082
|
+
function toNoArgVisit(visitFunction) {
|
|
1083
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1084
|
+
}
|
|
1085
|
+
function toOneArgVisit(visitFunction) {
|
|
1086
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1087
|
+
}
|
|
1088
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
1089
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
1090
|
+
}
|
|
1091
|
+
function toBeginVisit(visitFunction) {
|
|
1092
|
+
return visitFunction ? () => {
|
|
1093
|
+
if (suppressedCallbacks > 0) {
|
|
1094
|
+
suppressedCallbacks++;
|
|
1095
|
+
} else {
|
|
1096
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
1097
|
+
if (cbReturn === false) {
|
|
1098
|
+
suppressedCallbacks = 1;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
} : () => true;
|
|
1102
|
+
}
|
|
1103
|
+
function toEndVisit(visitFunction) {
|
|
1104
|
+
return visitFunction ? () => {
|
|
1105
|
+
if (suppressedCallbacks > 0) {
|
|
1106
|
+
suppressedCallbacks--;
|
|
1107
|
+
}
|
|
1108
|
+
if (suppressedCallbacks === 0) {
|
|
1109
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
1110
|
+
}
|
|
1111
|
+
} : () => true;
|
|
1112
|
+
}
|
|
1113
|
+
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
1114
|
+
const disallowComments = options && options.disallowComments;
|
|
1115
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
1116
|
+
function scanNext() {
|
|
1117
|
+
while (true) {
|
|
1118
|
+
const token = _scanner.scan();
|
|
1119
|
+
switch (_scanner.getTokenError()) {
|
|
1120
|
+
case 4:
|
|
1121
|
+
handleError(
|
|
1122
|
+
14
|
|
1123
|
+
/* ParseErrorCode.InvalidUnicode */
|
|
1124
|
+
);
|
|
1125
|
+
break;
|
|
1126
|
+
case 5:
|
|
1127
|
+
handleError(
|
|
1128
|
+
15
|
|
1129
|
+
/* ParseErrorCode.InvalidEscapeCharacter */
|
|
1130
|
+
);
|
|
1131
|
+
break;
|
|
1132
|
+
case 3:
|
|
1133
|
+
handleError(
|
|
1134
|
+
13
|
|
1135
|
+
/* ParseErrorCode.UnexpectedEndOfNumber */
|
|
1136
|
+
);
|
|
1137
|
+
break;
|
|
1138
|
+
case 1:
|
|
1139
|
+
if (!disallowComments) {
|
|
1140
|
+
handleError(
|
|
1141
|
+
11
|
|
1142
|
+
/* ParseErrorCode.UnexpectedEndOfComment */
|
|
1143
|
+
);
|
|
1144
|
+
}
|
|
1145
|
+
break;
|
|
1146
|
+
case 2:
|
|
1147
|
+
handleError(
|
|
1148
|
+
12
|
|
1149
|
+
/* ParseErrorCode.UnexpectedEndOfString */
|
|
1150
|
+
);
|
|
1151
|
+
break;
|
|
1152
|
+
case 6:
|
|
1153
|
+
handleError(
|
|
1154
|
+
16
|
|
1155
|
+
/* ParseErrorCode.InvalidCharacter */
|
|
1156
|
+
);
|
|
1157
|
+
break;
|
|
1158
|
+
}
|
|
1159
|
+
switch (token) {
|
|
1160
|
+
case 12:
|
|
1161
|
+
case 13:
|
|
1162
|
+
if (disallowComments) {
|
|
1163
|
+
handleError(
|
|
1164
|
+
10
|
|
1165
|
+
/* ParseErrorCode.InvalidCommentToken */
|
|
1166
|
+
);
|
|
1167
|
+
} else {
|
|
1168
|
+
onComment();
|
|
1169
|
+
}
|
|
1170
|
+
break;
|
|
1171
|
+
case 16:
|
|
1172
|
+
handleError(
|
|
1173
|
+
1
|
|
1174
|
+
/* ParseErrorCode.InvalidSymbol */
|
|
1175
|
+
);
|
|
1176
|
+
break;
|
|
1177
|
+
case 15:
|
|
1178
|
+
case 14:
|
|
1179
|
+
break;
|
|
1180
|
+
default:
|
|
1181
|
+
return token;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
function handleError(error, skipUntilAfter = [], skipUntil2 = []) {
|
|
1186
|
+
onError(error);
|
|
1187
|
+
if (skipUntilAfter.length + skipUntil2.length > 0) {
|
|
1188
|
+
let token = _scanner.getToken();
|
|
1189
|
+
while (token !== 17) {
|
|
1190
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
1191
|
+
scanNext();
|
|
1192
|
+
break;
|
|
1193
|
+
} else if (skipUntil2.indexOf(token) !== -1) {
|
|
1194
|
+
break;
|
|
1195
|
+
}
|
|
1196
|
+
token = scanNext();
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
function parseString2(isValue) {
|
|
1201
|
+
const value = _scanner.getTokenValue();
|
|
1202
|
+
if (isValue) {
|
|
1203
|
+
onLiteralValue(value);
|
|
1204
|
+
} else {
|
|
1205
|
+
onObjectProperty(value);
|
|
1206
|
+
_jsonPath.push(value);
|
|
1207
|
+
}
|
|
1208
|
+
scanNext();
|
|
1209
|
+
return true;
|
|
1210
|
+
}
|
|
1211
|
+
function parseLiteral() {
|
|
1212
|
+
switch (_scanner.getToken()) {
|
|
1213
|
+
case 11:
|
|
1214
|
+
const tokenValue = _scanner.getTokenValue();
|
|
1215
|
+
let value = Number(tokenValue);
|
|
1216
|
+
if (isNaN(value)) {
|
|
1217
|
+
handleError(
|
|
1218
|
+
2
|
|
1219
|
+
/* ParseErrorCode.InvalidNumberFormat */
|
|
1220
|
+
);
|
|
1221
|
+
value = 0;
|
|
1222
|
+
}
|
|
1223
|
+
onLiteralValue(value);
|
|
1224
|
+
break;
|
|
1225
|
+
case 7:
|
|
1226
|
+
onLiteralValue(null);
|
|
1227
|
+
break;
|
|
1228
|
+
case 8:
|
|
1229
|
+
onLiteralValue(true);
|
|
1230
|
+
break;
|
|
1231
|
+
case 9:
|
|
1232
|
+
onLiteralValue(false);
|
|
1233
|
+
break;
|
|
1234
|
+
default:
|
|
1235
|
+
return false;
|
|
1236
|
+
}
|
|
1237
|
+
scanNext();
|
|
1238
|
+
return true;
|
|
1239
|
+
}
|
|
1240
|
+
function parseProperty() {
|
|
1241
|
+
if (_scanner.getToken() !== 10) {
|
|
1242
|
+
handleError(3, [], [
|
|
1243
|
+
2,
|
|
1244
|
+
5
|
|
1245
|
+
/* SyntaxKind.CommaToken */
|
|
1246
|
+
]);
|
|
1247
|
+
return false;
|
|
1248
|
+
}
|
|
1249
|
+
parseString2(false);
|
|
1250
|
+
if (_scanner.getToken() === 6) {
|
|
1251
|
+
onSeparator(":");
|
|
1252
|
+
scanNext();
|
|
1253
|
+
if (!parseValue2()) {
|
|
1254
|
+
handleError(4, [], [
|
|
1255
|
+
2,
|
|
1256
|
+
5
|
|
1257
|
+
/* SyntaxKind.CommaToken */
|
|
1258
|
+
]);
|
|
1259
|
+
}
|
|
1260
|
+
} else {
|
|
1261
|
+
handleError(5, [], [
|
|
1262
|
+
2,
|
|
1263
|
+
5
|
|
1264
|
+
/* SyntaxKind.CommaToken */
|
|
1265
|
+
]);
|
|
1266
|
+
}
|
|
1267
|
+
_jsonPath.pop();
|
|
1268
|
+
return true;
|
|
1269
|
+
}
|
|
1270
|
+
function parseObject() {
|
|
1271
|
+
onObjectBegin();
|
|
1272
|
+
scanNext();
|
|
1273
|
+
let needsComma = false;
|
|
1274
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
1275
|
+
if (_scanner.getToken() === 5) {
|
|
1276
|
+
if (!needsComma) {
|
|
1277
|
+
handleError(4, [], []);
|
|
1278
|
+
}
|
|
1279
|
+
onSeparator(",");
|
|
1280
|
+
scanNext();
|
|
1281
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
1282
|
+
break;
|
|
1283
|
+
}
|
|
1284
|
+
} else if (needsComma) {
|
|
1285
|
+
handleError(6, [], []);
|
|
1286
|
+
}
|
|
1287
|
+
if (!parseProperty()) {
|
|
1288
|
+
handleError(4, [], [
|
|
1289
|
+
2,
|
|
1290
|
+
5
|
|
1291
|
+
/* SyntaxKind.CommaToken */
|
|
1292
|
+
]);
|
|
1293
|
+
}
|
|
1294
|
+
needsComma = true;
|
|
1295
|
+
}
|
|
1296
|
+
onObjectEnd();
|
|
1297
|
+
if (_scanner.getToken() !== 2) {
|
|
1298
|
+
handleError(7, [
|
|
1299
|
+
2
|
|
1300
|
+
/* SyntaxKind.CloseBraceToken */
|
|
1301
|
+
], []);
|
|
1302
|
+
} else {
|
|
1303
|
+
scanNext();
|
|
1304
|
+
}
|
|
1305
|
+
return true;
|
|
1306
|
+
}
|
|
1307
|
+
function parseArray2() {
|
|
1308
|
+
onArrayBegin();
|
|
1309
|
+
scanNext();
|
|
1310
|
+
let isFirstElement = true;
|
|
1311
|
+
let needsComma = false;
|
|
1312
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
1313
|
+
if (_scanner.getToken() === 5) {
|
|
1314
|
+
if (!needsComma) {
|
|
1315
|
+
handleError(4, [], []);
|
|
1316
|
+
}
|
|
1317
|
+
onSeparator(",");
|
|
1318
|
+
scanNext();
|
|
1319
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
1320
|
+
break;
|
|
1321
|
+
}
|
|
1322
|
+
} else if (needsComma) {
|
|
1323
|
+
handleError(6, [], []);
|
|
1324
|
+
}
|
|
1325
|
+
if (isFirstElement) {
|
|
1326
|
+
_jsonPath.push(0);
|
|
1327
|
+
isFirstElement = false;
|
|
1328
|
+
} else {
|
|
1329
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
1330
|
+
}
|
|
1331
|
+
if (!parseValue2()) {
|
|
1332
|
+
handleError(4, [], [
|
|
1333
|
+
4,
|
|
1334
|
+
5
|
|
1335
|
+
/* SyntaxKind.CommaToken */
|
|
1336
|
+
]);
|
|
1337
|
+
}
|
|
1338
|
+
needsComma = true;
|
|
1339
|
+
}
|
|
1340
|
+
onArrayEnd();
|
|
1341
|
+
if (!isFirstElement) {
|
|
1342
|
+
_jsonPath.pop();
|
|
1343
|
+
}
|
|
1344
|
+
if (_scanner.getToken() !== 4) {
|
|
1345
|
+
handleError(8, [
|
|
1346
|
+
4
|
|
1347
|
+
/* SyntaxKind.CloseBracketToken */
|
|
1348
|
+
], []);
|
|
1349
|
+
} else {
|
|
1350
|
+
scanNext();
|
|
1351
|
+
}
|
|
1352
|
+
return true;
|
|
1353
|
+
}
|
|
1354
|
+
function parseValue2() {
|
|
1355
|
+
switch (_scanner.getToken()) {
|
|
1356
|
+
case 3:
|
|
1357
|
+
return parseArray2();
|
|
1358
|
+
case 1:
|
|
1359
|
+
return parseObject();
|
|
1360
|
+
case 10:
|
|
1361
|
+
return parseString2(true);
|
|
1362
|
+
default:
|
|
1363
|
+
return parseLiteral();
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
scanNext();
|
|
1367
|
+
if (_scanner.getToken() === 17) {
|
|
1368
|
+
if (options.allowEmptyContent) {
|
|
1369
|
+
return true;
|
|
1370
|
+
}
|
|
1371
|
+
handleError(4, [], []);
|
|
1372
|
+
return false;
|
|
1373
|
+
}
|
|
1374
|
+
if (!parseValue2()) {
|
|
1375
|
+
handleError(4, [], []);
|
|
1376
|
+
return false;
|
|
1377
|
+
}
|
|
1378
|
+
if (_scanner.getToken() !== 17) {
|
|
1379
|
+
handleError(9, [], []);
|
|
1380
|
+
}
|
|
1381
|
+
return true;
|
|
1382
|
+
}
|
|
1383
|
+
function getNodeType(value) {
|
|
1384
|
+
switch (typeof value) {
|
|
1385
|
+
case "boolean":
|
|
1386
|
+
return "boolean";
|
|
1387
|
+
case "number":
|
|
1388
|
+
return "number";
|
|
1389
|
+
case "string":
|
|
1390
|
+
return "string";
|
|
1391
|
+
case "object": {
|
|
1392
|
+
if (!value) {
|
|
1393
|
+
return "null";
|
|
1394
|
+
} else if (Array.isArray(value)) {
|
|
1395
|
+
return "array";
|
|
1396
|
+
}
|
|
1397
|
+
return "object";
|
|
1398
|
+
}
|
|
1399
|
+
default:
|
|
1400
|
+
return "null";
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
// ../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/edit.js
|
|
1405
|
+
function setProperty(text, originalPath, value, options) {
|
|
1406
|
+
const path = originalPath.slice();
|
|
1407
|
+
const errors = [];
|
|
1408
|
+
const root = parseTree(text, errors);
|
|
1409
|
+
let parent = void 0;
|
|
1410
|
+
let lastSegment = void 0;
|
|
1411
|
+
while (path.length > 0) {
|
|
1412
|
+
lastSegment = path.pop();
|
|
1413
|
+
parent = findNodeAtLocation(root, path);
|
|
1414
|
+
if (parent === void 0 && value !== void 0) {
|
|
1415
|
+
if (typeof lastSegment === "string") {
|
|
1416
|
+
value = { [lastSegment]: value };
|
|
1417
|
+
} else {
|
|
1418
|
+
value = [value];
|
|
1419
|
+
}
|
|
1420
|
+
} else {
|
|
1421
|
+
break;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
if (!parent) {
|
|
1425
|
+
if (value === void 0) {
|
|
1426
|
+
throw new Error("Can not delete in empty document");
|
|
1427
|
+
}
|
|
1428
|
+
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
|
|
1429
|
+
} else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
|
|
1430
|
+
const existing = findNodeAtLocation(parent, [lastSegment]);
|
|
1431
|
+
if (existing !== void 0) {
|
|
1432
|
+
if (value === void 0) {
|
|
1433
|
+
if (!existing.parent) {
|
|
1434
|
+
throw new Error("Malformed AST");
|
|
1435
|
+
}
|
|
1436
|
+
const propertyIndex = parent.children.indexOf(existing.parent);
|
|
1437
|
+
let removeBegin;
|
|
1438
|
+
let removeEnd = existing.parent.offset + existing.parent.length;
|
|
1439
|
+
if (propertyIndex > 0) {
|
|
1440
|
+
let previous = parent.children[propertyIndex - 1];
|
|
1441
|
+
removeBegin = previous.offset + previous.length;
|
|
1442
|
+
} else {
|
|
1443
|
+
removeBegin = parent.offset + 1;
|
|
1444
|
+
if (parent.children.length > 1) {
|
|
1445
|
+
let next = parent.children[1];
|
|
1446
|
+
removeEnd = next.offset;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: "" }, options);
|
|
1450
|
+
} else {
|
|
1451
|
+
return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
|
|
1452
|
+
}
|
|
1453
|
+
} else {
|
|
1454
|
+
if (value === void 0) {
|
|
1455
|
+
return [];
|
|
1456
|
+
}
|
|
1457
|
+
const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
|
|
1458
|
+
const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
|
|
1459
|
+
let edit;
|
|
1460
|
+
if (index > 0) {
|
|
1461
|
+
let previous = parent.children[index - 1];
|
|
1462
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1463
|
+
} else if (parent.children.length === 0) {
|
|
1464
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1465
|
+
} else {
|
|
1466
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty + "," };
|
|
1467
|
+
}
|
|
1468
|
+
return withFormatting(text, edit, options);
|
|
1469
|
+
}
|
|
1470
|
+
} else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
|
|
1471
|
+
const insertIndex = lastSegment;
|
|
1472
|
+
if (insertIndex === -1) {
|
|
1473
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1474
|
+
let edit;
|
|
1475
|
+
if (parent.children.length === 0) {
|
|
1476
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1477
|
+
} else {
|
|
1478
|
+
const previous = parent.children[parent.children.length - 1];
|
|
1479
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1480
|
+
}
|
|
1481
|
+
return withFormatting(text, edit, options);
|
|
1482
|
+
} else if (value === void 0 && parent.children.length >= 0) {
|
|
1483
|
+
const removalIndex = lastSegment;
|
|
1484
|
+
const toRemove = parent.children[removalIndex];
|
|
1485
|
+
let edit;
|
|
1486
|
+
if (parent.children.length === 1) {
|
|
1487
|
+
edit = { offset: parent.offset + 1, length: parent.length - 2, content: "" };
|
|
1488
|
+
} else if (parent.children.length - 1 === removalIndex) {
|
|
1489
|
+
let previous = parent.children[removalIndex - 1];
|
|
1490
|
+
let offset = previous.offset + previous.length;
|
|
1491
|
+
let parentEndOffset = parent.offset + parent.length;
|
|
1492
|
+
edit = { offset, length: parentEndOffset - 2 - offset, content: "" };
|
|
1493
|
+
} else {
|
|
1494
|
+
edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: "" };
|
|
1495
|
+
}
|
|
1496
|
+
return withFormatting(text, edit, options);
|
|
1497
|
+
} else if (value !== void 0) {
|
|
1498
|
+
let edit;
|
|
1499
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1500
|
+
if (!options.isArrayInsertion && parent.children.length > lastSegment) {
|
|
1501
|
+
const toModify = parent.children[lastSegment];
|
|
1502
|
+
edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
|
|
1503
|
+
} else if (parent.children.length === 0 || lastSegment === 0) {
|
|
1504
|
+
edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + "," };
|
|
1505
|
+
} else {
|
|
1506
|
+
const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
|
|
1507
|
+
const previous = parent.children[index - 1];
|
|
1508
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1509
|
+
}
|
|
1510
|
+
return withFormatting(text, edit, options);
|
|
1511
|
+
} else {
|
|
1512
|
+
throw new Error(`Can not ${value === void 0 ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
|
|
1513
|
+
}
|
|
1514
|
+
} else {
|
|
1515
|
+
throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
function withFormatting(text, edit, options) {
|
|
1519
|
+
if (!options.formattingOptions) {
|
|
1520
|
+
return [edit];
|
|
1521
|
+
}
|
|
1522
|
+
let newText = applyEdit(text, edit);
|
|
1523
|
+
let begin = edit.offset;
|
|
1524
|
+
let end = edit.offset + edit.content.length;
|
|
1525
|
+
if (edit.length === 0 || edit.content.length === 0) {
|
|
1526
|
+
while (begin > 0 && !isEOL(newText, begin - 1)) {
|
|
1527
|
+
begin--;
|
|
1528
|
+
}
|
|
1529
|
+
while (end < newText.length && !isEOL(newText, end)) {
|
|
1530
|
+
end++;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
|
|
1534
|
+
for (let i = edits.length - 1; i >= 0; i--) {
|
|
1535
|
+
const edit2 = edits[i];
|
|
1536
|
+
newText = applyEdit(newText, edit2);
|
|
1537
|
+
begin = Math.min(begin, edit2.offset);
|
|
1538
|
+
end = Math.max(end, edit2.offset + edit2.length);
|
|
1539
|
+
end += edit2.content.length - edit2.length;
|
|
1540
|
+
}
|
|
1541
|
+
const editLength = text.length - (newText.length - end) - begin;
|
|
1542
|
+
return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
|
|
1543
|
+
}
|
|
1544
|
+
function applyEdit(text, edit) {
|
|
1545
|
+
return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
// ../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/main.js
|
|
1549
|
+
var ScanError;
|
|
1550
|
+
(function(ScanError2) {
|
|
1551
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
1552
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
1553
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
1554
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
1555
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
1556
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
1557
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
1558
|
+
})(ScanError || (ScanError = {}));
|
|
1559
|
+
var SyntaxKind;
|
|
1560
|
+
(function(SyntaxKind2) {
|
|
1561
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
1562
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
1563
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
1564
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
1565
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
1566
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
1567
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
1568
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
1569
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
1570
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
1571
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
1572
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
1573
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
1574
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
1575
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
1576
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
1577
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
1578
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
1579
|
+
var parse2 = parse;
|
|
1580
|
+
var ParseErrorCode;
|
|
1581
|
+
(function(ParseErrorCode2) {
|
|
1582
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
1583
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
1584
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
1585
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
1586
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
1587
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
1588
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
1589
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
1590
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
1591
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
1592
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
1593
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
1594
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
1595
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
1596
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
1597
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
1598
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
1599
|
+
function printParseErrorCode(code) {
|
|
1600
|
+
switch (code) {
|
|
1601
|
+
case 1:
|
|
1602
|
+
return "InvalidSymbol";
|
|
1603
|
+
case 2:
|
|
1604
|
+
return "InvalidNumberFormat";
|
|
1605
|
+
case 3:
|
|
1606
|
+
return "PropertyNameExpected";
|
|
1607
|
+
case 4:
|
|
1608
|
+
return "ValueExpected";
|
|
1609
|
+
case 5:
|
|
1610
|
+
return "ColonExpected";
|
|
1611
|
+
case 6:
|
|
1612
|
+
return "CommaExpected";
|
|
1613
|
+
case 7:
|
|
1614
|
+
return "CloseBraceExpected";
|
|
1615
|
+
case 8:
|
|
1616
|
+
return "CloseBracketExpected";
|
|
1617
|
+
case 9:
|
|
1618
|
+
return "EndOfFileExpected";
|
|
1619
|
+
case 10:
|
|
1620
|
+
return "InvalidCommentToken";
|
|
1621
|
+
case 11:
|
|
1622
|
+
return "UnexpectedEndOfComment";
|
|
1623
|
+
case 12:
|
|
1624
|
+
return "UnexpectedEndOfString";
|
|
1625
|
+
case 13:
|
|
1626
|
+
return "UnexpectedEndOfNumber";
|
|
1627
|
+
case 14:
|
|
1628
|
+
return "InvalidUnicode";
|
|
1629
|
+
case 15:
|
|
1630
|
+
return "InvalidEscapeCharacter";
|
|
1631
|
+
case 16:
|
|
1632
|
+
return "InvalidCharacter";
|
|
1633
|
+
}
|
|
1634
|
+
return "<unknown ParseErrorCode>";
|
|
1635
|
+
}
|
|
1636
|
+
function modify(text, path, value, options) {
|
|
1637
|
+
return setProperty(text, path, value, options);
|
|
1638
|
+
}
|
|
1639
|
+
function applyEdits(text, edits) {
|
|
1640
|
+
let sortedEdits = edits.slice(0).sort((a, b) => {
|
|
1641
|
+
const diff = a.offset - b.offset;
|
|
1642
|
+
if (diff === 0) {
|
|
1643
|
+
return a.length - b.length;
|
|
1644
|
+
}
|
|
1645
|
+
return diff;
|
|
1646
|
+
});
|
|
1647
|
+
let lastModifiedOffset = text.length;
|
|
1648
|
+
for (let i = sortedEdits.length - 1; i >= 0; i--) {
|
|
1649
|
+
let e = sortedEdits[i];
|
|
1650
|
+
if (e.offset + e.length <= lastModifiedOffset) {
|
|
1651
|
+
text = applyEdit(text, e);
|
|
1652
|
+
} else {
|
|
1653
|
+
throw new Error("Overlapping edit");
|
|
1654
|
+
}
|
|
1655
|
+
lastModifiedOffset = e.offset;
|
|
1656
|
+
}
|
|
1657
|
+
return text;
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
// scripts/permissions.ts
|
|
1661
|
+
import {
|
|
1662
|
+
chmodSync,
|
|
1663
|
+
existsSync as existsSync3,
|
|
1664
|
+
lstatSync,
|
|
1665
|
+
mkdirSync as mkdirSync2,
|
|
1666
|
+
realpathSync,
|
|
1667
|
+
renameSync,
|
|
1668
|
+
statSync,
|
|
1669
|
+
unlinkSync,
|
|
1670
|
+
writeFileSync as writeFileSync2,
|
|
1671
|
+
readFileSync as readFileSync3
|
|
1672
|
+
} from "node:fs";
|
|
1673
|
+
import { basename, dirname as dirname3 } from "node:path";
|
|
1674
|
+
|
|
1675
|
+
// ../node_modules/.pnpm/smol-toml@1.7.1/node_modules/smol-toml/dist/date.js
|
|
1676
|
+
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
|
|
1677
|
+
var TomlDate = class _TomlDate extends Date {
|
|
1678
|
+
#hasDate = false;
|
|
1679
|
+
#hasTime = false;
|
|
1680
|
+
#offset = null;
|
|
1681
|
+
constructor(date) {
|
|
1682
|
+
let hasDate = true;
|
|
1683
|
+
let hasTime = true;
|
|
1684
|
+
let offset = "Z";
|
|
1685
|
+
if (typeof date === "string") {
|
|
1686
|
+
let match = date.match(DATE_TIME_RE);
|
|
1687
|
+
if (match) {
|
|
1688
|
+
if (!match[1]) {
|
|
1689
|
+
hasDate = false;
|
|
1690
|
+
date = `0000-01-01T${date}`;
|
|
1691
|
+
}
|
|
1692
|
+
hasTime = !!match[2];
|
|
1693
|
+
hasTime && date[10] === " " && (date = date.replace(" ", "T"));
|
|
1694
|
+
if (match[2] && +match[2] > 23) {
|
|
1695
|
+
date = "";
|
|
1696
|
+
} else {
|
|
1697
|
+
offset = match[3] || null;
|
|
1698
|
+
date = date.toUpperCase();
|
|
1699
|
+
if (!offset && hasTime)
|
|
1700
|
+
date += "Z";
|
|
1701
|
+
}
|
|
1702
|
+
} else {
|
|
1703
|
+
date = "";
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
super(date);
|
|
1707
|
+
if (!isNaN(this.getTime())) {
|
|
1708
|
+
this.#hasDate = hasDate;
|
|
1709
|
+
this.#hasTime = hasTime;
|
|
1710
|
+
this.#offset = offset;
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
isDateTime() {
|
|
1714
|
+
return this.#hasDate && this.#hasTime;
|
|
1715
|
+
}
|
|
1716
|
+
isLocal() {
|
|
1717
|
+
return !this.#hasDate || !this.#hasTime || !this.#offset;
|
|
1718
|
+
}
|
|
1719
|
+
isDate() {
|
|
1720
|
+
return this.#hasDate && !this.#hasTime;
|
|
1721
|
+
}
|
|
1722
|
+
isTime() {
|
|
1723
|
+
return this.#hasTime && !this.#hasDate;
|
|
1724
|
+
}
|
|
1725
|
+
isValid() {
|
|
1726
|
+
return this.#hasDate || this.#hasTime;
|
|
1727
|
+
}
|
|
1728
|
+
toISOString() {
|
|
1729
|
+
let iso = super.toISOString();
|
|
1730
|
+
if (this.isDate())
|
|
1731
|
+
return iso.slice(0, 10);
|
|
1732
|
+
if (this.isTime())
|
|
1733
|
+
return iso.slice(11, 23);
|
|
1734
|
+
if (this.#offset === null)
|
|
1735
|
+
return iso.slice(0, -1);
|
|
1736
|
+
if (this.#offset === "Z")
|
|
1737
|
+
return iso;
|
|
1738
|
+
let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
|
|
1739
|
+
offset = this.#offset[0] === "-" ? offset : -offset;
|
|
1740
|
+
let offsetDate = new Date(this.getTime() - offset * 6e4);
|
|
1741
|
+
return offsetDate.toISOString().slice(0, -1) + this.#offset;
|
|
1742
|
+
}
|
|
1743
|
+
static wrapAsOffsetDateTime(jsDate, offset = "Z") {
|
|
1744
|
+
let date = new _TomlDate(jsDate);
|
|
1745
|
+
date.#offset = offset;
|
|
1746
|
+
return date;
|
|
1747
|
+
}
|
|
1748
|
+
static wrapAsLocalDateTime(jsDate) {
|
|
1749
|
+
let date = new _TomlDate(jsDate);
|
|
1750
|
+
date.#offset = null;
|
|
1751
|
+
return date;
|
|
1752
|
+
}
|
|
1753
|
+
static wrapAsLocalDate(jsDate) {
|
|
1754
|
+
let date = new _TomlDate(jsDate);
|
|
1755
|
+
date.#hasTime = false;
|
|
1756
|
+
date.#offset = null;
|
|
1757
|
+
return date;
|
|
1758
|
+
}
|
|
1759
|
+
static wrapAsLocalTime(jsDate) {
|
|
1760
|
+
let date = new _TomlDate(jsDate);
|
|
1761
|
+
date.#hasDate = false;
|
|
1762
|
+
date.#offset = null;
|
|
1763
|
+
return date;
|
|
1764
|
+
}
|
|
1765
|
+
};
|
|
1766
|
+
|
|
1767
|
+
// ../node_modules/.pnpm/smol-toml@1.7.1/node_modules/smol-toml/dist/error.js
|
|
1768
|
+
function getLineColFromPtr(string, ptr) {
|
|
1769
|
+
let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g);
|
|
1770
|
+
return [lines.length, lines.pop().length + 1];
|
|
1771
|
+
}
|
|
1772
|
+
function makeCodeBlock(string, line, column) {
|
|
1773
|
+
let lines = string.split(/\r\n|\n|\r/g);
|
|
1774
|
+
let codeblock = "";
|
|
1775
|
+
let numberLen = (Math.log10(line + 1) | 0) + 1;
|
|
1776
|
+
for (let i = line - 1; i <= line + 1; i++) {
|
|
1777
|
+
let l = lines[i - 1];
|
|
1778
|
+
if (!l)
|
|
1779
|
+
continue;
|
|
1780
|
+
codeblock += i.toString().padEnd(numberLen, " ");
|
|
1781
|
+
codeblock += ": ";
|
|
1782
|
+
codeblock += l;
|
|
1783
|
+
codeblock += "\n";
|
|
1784
|
+
if (i === line) {
|
|
1785
|
+
codeblock += " ".repeat(numberLen + column + 2);
|
|
1786
|
+
codeblock += "^\n";
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
return codeblock;
|
|
1790
|
+
}
|
|
1791
|
+
var TomlError = class extends Error {
|
|
1792
|
+
line;
|
|
1793
|
+
column;
|
|
1794
|
+
codeblock;
|
|
1795
|
+
constructor(message, options) {
|
|
1796
|
+
const [line, column] = getLineColFromPtr(options.toml, options.ptr);
|
|
1797
|
+
const codeblock = makeCodeBlock(options.toml, line, column);
|
|
1798
|
+
super(`Invalid TOML document: ${message}
|
|
1799
|
+
|
|
1800
|
+
${codeblock}`, options);
|
|
1801
|
+
this.line = line;
|
|
1802
|
+
this.column = column;
|
|
1803
|
+
this.codeblock = codeblock;
|
|
1804
|
+
}
|
|
1805
|
+
};
|
|
1806
|
+
|
|
1807
|
+
// ../node_modules/.pnpm/smol-toml@1.7.1/node_modules/smol-toml/dist/primitive.js
|
|
1808
|
+
var INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
|
|
1809
|
+
var FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
|
|
1810
|
+
var LEADING_ZERO = /^[+-]?0[0-9_]/;
|
|
1811
|
+
function parseString(str, ptr) {
|
|
1812
|
+
let c = str[ptr++];
|
|
1813
|
+
let first = c;
|
|
1814
|
+
let isLiteral = c === "'";
|
|
1815
|
+
let isMultiline = c === str[ptr] && c === str[ptr + 1];
|
|
1816
|
+
if (isMultiline) {
|
|
1817
|
+
if (str[ptr += 2] === "\n")
|
|
1818
|
+
ptr++;
|
|
1819
|
+
else if (str[ptr] === "\r" && str[ptr + 1] === "\n")
|
|
1820
|
+
ptr += 2;
|
|
1821
|
+
}
|
|
1822
|
+
let parsed = "";
|
|
1823
|
+
let sliceStart = ptr;
|
|
1824
|
+
let state = 0;
|
|
1825
|
+
for (let i = ptr; i < str.length; i++) {
|
|
1826
|
+
c = str[i];
|
|
1827
|
+
if (isMultiline && (c === "\n" || c === "\r" && str[i + 1] === "\n")) {
|
|
1828
|
+
state = state && 3;
|
|
1829
|
+
} else if (c < " " && c !== " " || c === "\x7F") {
|
|
1830
|
+
throw new TomlError("control characters are not allowed in strings", {
|
|
1831
|
+
toml: str,
|
|
1832
|
+
ptr: i
|
|
1833
|
+
});
|
|
1834
|
+
} else if ((!state || state === 3) && c === first && (!isMultiline || str[i + 1] === first && str[i + 2] === first)) {
|
|
1835
|
+
if (isMultiline) {
|
|
1836
|
+
if (str[i + 3] === first)
|
|
1837
|
+
i++;
|
|
1838
|
+
if (str[i + 3] === first)
|
|
1839
|
+
i++;
|
|
1840
|
+
}
|
|
1841
|
+
return [
|
|
1842
|
+
// If we're in a newline escape still, then there's nothing to add.
|
|
1843
|
+
// Also try to avoid concat if there's nothing to add to parsed, or nothing has been added to parsed.
|
|
1844
|
+
state ? parsed : parsed + str.slice(sliceStart, i),
|
|
1845
|
+
i + (isMultiline ? 3 : 1)
|
|
1846
|
+
];
|
|
1847
|
+
} else if (!state) {
|
|
1848
|
+
if (!isLiteral && c === "\\") {
|
|
1849
|
+
parsed += str.slice(sliceStart, sliceStart = i);
|
|
1850
|
+
state = 1;
|
|
1851
|
+
}
|
|
1852
|
+
} else if (state === 1) {
|
|
1853
|
+
if (c === "x" || c === "u" || c === "U") {
|
|
1854
|
+
let value = 0;
|
|
1855
|
+
let len = c === "x" ? 2 : c === "u" ? 4 : 8;
|
|
1856
|
+
for (let j = 0; j < len; j++, i++) {
|
|
1857
|
+
let hex = str.charCodeAt(i + 1);
|
|
1858
|
+
let digit = (
|
|
1859
|
+
/* 0-9 */
|
|
1860
|
+
hex >= 48 && hex <= 57 ? hex - 48 : (
|
|
1861
|
+
/* A-F */
|
|
1862
|
+
hex >= 65 && hex <= 70 ? hex - 65 + 10 : (
|
|
1863
|
+
/* a-f */
|
|
1864
|
+
hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1
|
|
1865
|
+
)
|
|
1866
|
+
)
|
|
1867
|
+
);
|
|
1868
|
+
if (digit < 0)
|
|
1869
|
+
throw new TomlError("invalid non-hex character in unicode escape", { toml: str, ptr: i + 1 });
|
|
1870
|
+
value = value << 4 | digit;
|
|
1871
|
+
}
|
|
1872
|
+
if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) {
|
|
1873
|
+
throw new TomlError("invalid unicode escape", { toml: str, ptr: i });
|
|
1874
|
+
}
|
|
1875
|
+
parsed += String.fromCodePoint(value);
|
|
1876
|
+
sliceStart = i + 1;
|
|
1877
|
+
state = 0;
|
|
1878
|
+
} else if (c === " " || c === " ") {
|
|
1879
|
+
state = 2;
|
|
1880
|
+
} else {
|
|
1881
|
+
if (c === "b")
|
|
1882
|
+
parsed += "\b";
|
|
1883
|
+
else if (c === "t")
|
|
1884
|
+
parsed += " ";
|
|
1885
|
+
else if (c === "n")
|
|
1886
|
+
parsed += "\n";
|
|
1887
|
+
else if (c === "f")
|
|
1888
|
+
parsed += "\f";
|
|
1889
|
+
else if (c === "r")
|
|
1890
|
+
parsed += "\r";
|
|
1891
|
+
else if (c === "e")
|
|
1892
|
+
parsed += "\x1B";
|
|
1893
|
+
else if (c === '"')
|
|
1894
|
+
parsed += '"';
|
|
1895
|
+
else if (c === "\\")
|
|
1896
|
+
parsed += "\\";
|
|
1897
|
+
else
|
|
1898
|
+
throw new TomlError("unrecognized escape sequence", { toml: str, ptr: i });
|
|
1899
|
+
sliceStart = i + 1;
|
|
1900
|
+
state = 0;
|
|
1901
|
+
}
|
|
1902
|
+
} else if (c !== " " && c !== " ") {
|
|
1903
|
+
if (state === 2) {
|
|
1904
|
+
throw new TomlError("invalid escape: only line-ending whitespace may be escaped", {
|
|
1905
|
+
toml: str,
|
|
1906
|
+
ptr: sliceStart
|
|
1907
|
+
});
|
|
1908
|
+
}
|
|
1909
|
+
state = !isLiteral && c === "\\" ? 1 : 0;
|
|
1910
|
+
sliceStart = i;
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
throw new TomlError("unfinished string", { toml: str, ptr });
|
|
1914
|
+
}
|
|
1915
|
+
function parseValue(value, toml, ptr, integersAsBigInt) {
|
|
1916
|
+
if (value === "true")
|
|
1917
|
+
return true;
|
|
1918
|
+
if (value === "false")
|
|
1919
|
+
return false;
|
|
1920
|
+
if (value === "-inf")
|
|
1921
|
+
return -Infinity;
|
|
1922
|
+
if (value === "inf" || value === "+inf")
|
|
1923
|
+
return Infinity;
|
|
1924
|
+
if (value === "nan" || value === "+nan" || value === "-nan")
|
|
1925
|
+
return NaN;
|
|
1926
|
+
if (value === "-0")
|
|
1927
|
+
return integersAsBigInt ? 0n : 0;
|
|
1928
|
+
let isInt = INT_REGEX.test(value);
|
|
1929
|
+
if (isInt || FLOAT_REGEX.test(value)) {
|
|
1930
|
+
if (LEADING_ZERO.test(value)) {
|
|
1931
|
+
throw new TomlError("leading zeroes are not allowed", {
|
|
1932
|
+
toml,
|
|
1933
|
+
ptr
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
value = value.replace(/_/g, "");
|
|
1937
|
+
let numeric = +value;
|
|
1938
|
+
if (isNaN(numeric)) {
|
|
1939
|
+
throw new TomlError("invalid number", {
|
|
1940
|
+
toml,
|
|
1941
|
+
ptr
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
if (isInt) {
|
|
1945
|
+
if ((isInt = !Number.isSafeInteger(numeric)) && !integersAsBigInt) {
|
|
1946
|
+
throw new TomlError("integer value cannot be represented losslessly", {
|
|
1947
|
+
toml,
|
|
1948
|
+
ptr
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
if (isInt || integersAsBigInt === true)
|
|
1952
|
+
numeric = BigInt(value);
|
|
1953
|
+
}
|
|
1954
|
+
return numeric;
|
|
1955
|
+
}
|
|
1956
|
+
const date = new TomlDate(value);
|
|
1957
|
+
if (!date.isValid()) {
|
|
1958
|
+
throw new TomlError("invalid value", {
|
|
1959
|
+
toml,
|
|
1960
|
+
ptr
|
|
1961
|
+
});
|
|
1962
|
+
}
|
|
1963
|
+
return date;
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
// ../node_modules/.pnpm/smol-toml@1.7.1/node_modules/smol-toml/dist/util.js
|
|
1967
|
+
function indexOfNewline(str, start = 0, end = str.length) {
|
|
1968
|
+
let idx = str.indexOf("\n", start);
|
|
1969
|
+
if (str[idx - 1] === "\r")
|
|
1970
|
+
idx--;
|
|
1971
|
+
return idx <= end ? idx : -1;
|
|
1972
|
+
}
|
|
1973
|
+
function skipComment(str, ptr) {
|
|
1974
|
+
for (let i = ptr; i < str.length; i++) {
|
|
1975
|
+
let c = str[i];
|
|
1976
|
+
if (c === "\n")
|
|
1977
|
+
return i;
|
|
1978
|
+
if (c === "\r" && str[i + 1] === "\n")
|
|
1979
|
+
return i + 1;
|
|
1980
|
+
if (c < " " && c !== " " || c === "\x7F") {
|
|
1981
|
+
throw new TomlError("control characters are not allowed in comments", {
|
|
1982
|
+
toml: str,
|
|
1983
|
+
ptr
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
return str.length;
|
|
1988
|
+
}
|
|
1989
|
+
function skipVoid(str, ptr, banNewLines, banComments) {
|
|
1990
|
+
let c;
|
|
1991
|
+
while (1) {
|
|
1992
|
+
while ((c = str[ptr]) === " " || c === " " || !banNewLines && (c === "\n" || c === "\r" && str[ptr + 1] === "\n"))
|
|
1993
|
+
ptr++;
|
|
1994
|
+
if (banComments || c !== "#")
|
|
1995
|
+
break;
|
|
1996
|
+
ptr = skipComment(str, ptr);
|
|
1997
|
+
}
|
|
1998
|
+
return ptr;
|
|
1999
|
+
}
|
|
2000
|
+
function skipUntil(str, ptr, sep2, end, banNewLines = false) {
|
|
2001
|
+
if (!end) {
|
|
2002
|
+
ptr = indexOfNewline(str, ptr);
|
|
2003
|
+
return ptr < 0 ? str.length : ptr;
|
|
2004
|
+
}
|
|
2005
|
+
for (let i = ptr; i < str.length; i++) {
|
|
2006
|
+
let c = str[i];
|
|
2007
|
+
if (c === "#") {
|
|
2008
|
+
i = indexOfNewline(str, i);
|
|
2009
|
+
if (i < 0)
|
|
2010
|
+
break;
|
|
2011
|
+
} else if (c === sep2) {
|
|
2012
|
+
return i + 1;
|
|
2013
|
+
} else if (c === end || banNewLines && (c === "\n" || c === "\r" && str[i + 1] === "\n")) {
|
|
2014
|
+
return i;
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
throw new TomlError("cannot find end of structure", {
|
|
2018
|
+
toml: str,
|
|
2019
|
+
ptr
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
// ../node_modules/.pnpm/smol-toml@1.7.1/node_modules/smol-toml/dist/extract.js
|
|
2024
|
+
function sliceAndTrimEndOf(str, startPtr, endPtr) {
|
|
2025
|
+
let value = str.slice(startPtr, endPtr);
|
|
2026
|
+
let commentIdx = value.indexOf("#");
|
|
2027
|
+
if (commentIdx > -1) {
|
|
2028
|
+
skipComment(str, commentIdx);
|
|
2029
|
+
value = value.slice(0, commentIdx);
|
|
2030
|
+
}
|
|
2031
|
+
return [value.trimEnd(), commentIdx];
|
|
2032
|
+
}
|
|
2033
|
+
function extractValue(str, ptr, end, depth, integersAsBigInt) {
|
|
2034
|
+
if (depth === 0) {
|
|
2035
|
+
throw new TomlError("document contains excessively nested structures. aborting.", {
|
|
2036
|
+
toml: str,
|
|
2037
|
+
ptr
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
2040
|
+
let c = str[ptr];
|
|
2041
|
+
if (c === "[" || c === "{") {
|
|
2042
|
+
let [value, endPtr2] = c === "[" ? parseArray(str, ptr, depth, integersAsBigInt) : parseInlineTable(str, ptr, depth, integersAsBigInt);
|
|
2043
|
+
if (end) {
|
|
2044
|
+
endPtr2 = skipVoid(str, endPtr2);
|
|
2045
|
+
if (str[endPtr2] === ",")
|
|
2046
|
+
endPtr2++;
|
|
2047
|
+
else if (str[endPtr2] !== end) {
|
|
2048
|
+
throw new TomlError("expected comma or end of structure", {
|
|
2049
|
+
toml: str,
|
|
2050
|
+
ptr: endPtr2
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
return [value, endPtr2];
|
|
2055
|
+
}
|
|
2056
|
+
if (c === '"' || c === "'") {
|
|
2057
|
+
let [parsed, endPtr2] = parseString(str, ptr);
|
|
2058
|
+
if (end) {
|
|
2059
|
+
endPtr2 = skipVoid(str, endPtr2);
|
|
2060
|
+
if (str[endPtr2] && str[endPtr2] !== "," && str[endPtr2] !== end && str[endPtr2] !== "\n" && str[endPtr2] !== "\r") {
|
|
2061
|
+
throw new TomlError("unexpected character encountered", {
|
|
2062
|
+
toml: str,
|
|
2063
|
+
ptr: endPtr2
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
if (str[endPtr2] === ",")
|
|
2067
|
+
endPtr2++;
|
|
2068
|
+
}
|
|
2069
|
+
return [parsed, endPtr2];
|
|
2070
|
+
}
|
|
2071
|
+
let endPtr = skipUntil(str, ptr, ",", end);
|
|
2072
|
+
let slice = sliceAndTrimEndOf(str, ptr, endPtr - (str[endPtr - 1] === "," ? 1 : 0));
|
|
2073
|
+
if (!slice[0]) {
|
|
2074
|
+
throw new TomlError("incomplete key-value declaration: no value specified", {
|
|
2075
|
+
toml: str,
|
|
2076
|
+
ptr
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
if (end && slice[1] > -1) {
|
|
2080
|
+
endPtr = skipVoid(str, ptr + slice[1]);
|
|
2081
|
+
if (str[endPtr] === ",")
|
|
2082
|
+
endPtr++;
|
|
2083
|
+
}
|
|
2084
|
+
return [
|
|
2085
|
+
parseValue(slice[0], str, ptr, integersAsBigInt),
|
|
2086
|
+
endPtr
|
|
2087
|
+
];
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
// ../node_modules/.pnpm/smol-toml@1.7.1/node_modules/smol-toml/dist/struct.js
|
|
2091
|
+
var KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/;
|
|
2092
|
+
function parseKey(str, ptr, end = "=") {
|
|
2093
|
+
let dot = ptr - 1;
|
|
2094
|
+
let parsed = [];
|
|
2095
|
+
let endPtr = str.indexOf(end, ptr);
|
|
2096
|
+
if (endPtr < 0) {
|
|
2097
|
+
throw new TomlError("incomplete key-value: cannot find end of key", {
|
|
2098
|
+
toml: str,
|
|
2099
|
+
ptr
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
do {
|
|
2103
|
+
let c = str[ptr = ++dot];
|
|
2104
|
+
if (c !== " " && c !== " ") {
|
|
2105
|
+
if (c === '"' || c === "'") {
|
|
2106
|
+
if (c === str[ptr + 1] && c === str[ptr + 2]) {
|
|
2107
|
+
throw new TomlError("multiline strings are not allowed in keys", {
|
|
2108
|
+
toml: str,
|
|
2109
|
+
ptr
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
let [part, eos] = parseString(str, ptr);
|
|
2113
|
+
dot = str.indexOf(".", eos);
|
|
2114
|
+
let strEnd = str.slice(eos, dot < 0 || dot > endPtr ? endPtr : dot);
|
|
2115
|
+
let newLine = indexOfNewline(strEnd);
|
|
2116
|
+
if (newLine > -1) {
|
|
2117
|
+
throw new TomlError("newlines are not allowed in keys", {
|
|
2118
|
+
toml: str,
|
|
2119
|
+
ptr: ptr + dot + newLine
|
|
2120
|
+
});
|
|
2121
|
+
}
|
|
2122
|
+
if (strEnd.trimStart()) {
|
|
2123
|
+
throw new TomlError("found extra tokens after the string part", {
|
|
2124
|
+
toml: str,
|
|
2125
|
+
ptr: eos
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
if (endPtr < eos) {
|
|
2129
|
+
endPtr = str.indexOf(end, eos);
|
|
2130
|
+
if (endPtr < 0) {
|
|
2131
|
+
throw new TomlError("incomplete key-value: cannot find end of key", {
|
|
2132
|
+
toml: str,
|
|
2133
|
+
ptr
|
|
2134
|
+
});
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
parsed.push(part);
|
|
2138
|
+
} else {
|
|
2139
|
+
dot = str.indexOf(".", ptr);
|
|
2140
|
+
let part = str.slice(ptr, dot < 0 || dot > endPtr ? endPtr : dot);
|
|
2141
|
+
if (!KEY_PART_RE.test(part)) {
|
|
2142
|
+
throw new TomlError("only letter, numbers, dashes and underscores are allowed in keys", {
|
|
2143
|
+
toml: str,
|
|
2144
|
+
ptr
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
parsed.push(part.trimEnd());
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
} while (dot + 1 && dot < endPtr);
|
|
2151
|
+
return [parsed, skipVoid(str, endPtr + 1, true, true)];
|
|
2152
|
+
}
|
|
2153
|
+
function parseInlineTable(str, ptr, depth, integersAsBigInt) {
|
|
2154
|
+
let res = {};
|
|
2155
|
+
let seen = /* @__PURE__ */ new Set();
|
|
2156
|
+
let c;
|
|
2157
|
+
ptr++;
|
|
2158
|
+
while ((c = str[ptr++]) !== "}" && c) {
|
|
2159
|
+
if (c === ",") {
|
|
2160
|
+
throw new TomlError("expected value, found comma", {
|
|
2161
|
+
toml: str,
|
|
2162
|
+
ptr: ptr - 1
|
|
2163
|
+
});
|
|
2164
|
+
} else if (c === "#")
|
|
2165
|
+
ptr = skipComment(str, ptr);
|
|
2166
|
+
else if (c !== " " && c !== " " && c !== "\n" && c !== "\r") {
|
|
2167
|
+
let k;
|
|
2168
|
+
let t = res;
|
|
2169
|
+
let hasOwn = false;
|
|
2170
|
+
let [key, keyEndPtr] = parseKey(str, ptr - 1);
|
|
2171
|
+
for (let i = 0; i < key.length; i++) {
|
|
2172
|
+
if (i)
|
|
2173
|
+
t = hasOwn ? t[k] : t[k] = {};
|
|
2174
|
+
k = key[i];
|
|
2175
|
+
if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) {
|
|
2176
|
+
throw new TomlError("trying to redefine an already defined value", {
|
|
2177
|
+
toml: str,
|
|
2178
|
+
ptr
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
if (!hasOwn && k === "__proto__") {
|
|
2182
|
+
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
if (hasOwn) {
|
|
2186
|
+
throw new TomlError("trying to redefine an already defined value", {
|
|
2187
|
+
toml: str,
|
|
2188
|
+
ptr
|
|
2189
|
+
});
|
|
2190
|
+
}
|
|
2191
|
+
let [value, valueEndPtr] = extractValue(str, keyEndPtr, "}", depth - 1, integersAsBigInt);
|
|
2192
|
+
seen.add(value);
|
|
2193
|
+
t[k] = value;
|
|
2194
|
+
ptr = valueEndPtr;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
if (!c) {
|
|
2198
|
+
throw new TomlError("unfinished table encountered", {
|
|
2199
|
+
toml: str,
|
|
2200
|
+
ptr
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
return [res, ptr];
|
|
2204
|
+
}
|
|
2205
|
+
function parseArray(str, ptr, depth, integersAsBigInt) {
|
|
2206
|
+
let res = [];
|
|
2207
|
+
let c;
|
|
2208
|
+
ptr++;
|
|
2209
|
+
while ((c = str[ptr++]) !== "]" && c) {
|
|
2210
|
+
if (c === ",") {
|
|
2211
|
+
throw new TomlError("expected value, found comma", {
|
|
2212
|
+
toml: str,
|
|
2213
|
+
ptr: ptr - 1
|
|
2214
|
+
});
|
|
2215
|
+
} else if (c === "#")
|
|
2216
|
+
ptr = skipComment(str, ptr);
|
|
2217
|
+
else if (c !== " " && c !== " " && c !== "\n" && c !== "\r") {
|
|
2218
|
+
let e = extractValue(str, ptr - 1, "]", depth - 1, integersAsBigInt);
|
|
2219
|
+
res.push(e[0]);
|
|
2220
|
+
ptr = e[1];
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
if (!c) {
|
|
2224
|
+
throw new TomlError("unfinished array encountered", {
|
|
2225
|
+
toml: str,
|
|
2226
|
+
ptr
|
|
2227
|
+
});
|
|
2228
|
+
}
|
|
2229
|
+
return [res, ptr];
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
// ../node_modules/.pnpm/smol-toml@1.7.1/node_modules/smol-toml/dist/parse.js
|
|
2233
|
+
function peekTable(key, table, meta, type) {
|
|
2234
|
+
let t = table;
|
|
2235
|
+
let m = meta;
|
|
2236
|
+
let k;
|
|
2237
|
+
let hasOwn = false;
|
|
2238
|
+
let state;
|
|
2239
|
+
for (let i = 0; i < key.length; i++) {
|
|
2240
|
+
if (i) {
|
|
2241
|
+
t = hasOwn ? t[k] : t[k] = {};
|
|
2242
|
+
m = (state = m[k]).c;
|
|
2243
|
+
if (type === 0 && (state.t === 1 || state.t === 2)) {
|
|
2244
|
+
return null;
|
|
2245
|
+
}
|
|
2246
|
+
if (state.t === 2) {
|
|
2247
|
+
let l = t.length - 1;
|
|
2248
|
+
t = t[l];
|
|
2249
|
+
m = m[l].c;
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
k = key[i];
|
|
2253
|
+
if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) {
|
|
2254
|
+
return null;
|
|
2255
|
+
}
|
|
2256
|
+
if (!hasOwn) {
|
|
2257
|
+
if (k === "__proto__") {
|
|
2258
|
+
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
|
|
2259
|
+
Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
|
|
2260
|
+
}
|
|
2261
|
+
m[k] = {
|
|
2262
|
+
t: i < key.length - 1 && type === 2 ? 3 : type,
|
|
2263
|
+
d: false,
|
|
2264
|
+
i: 0,
|
|
2265
|
+
c: {}
|
|
2266
|
+
};
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
state = m[k];
|
|
2270
|
+
if (state.t !== type && !(type === 1 && state.t === 3)) {
|
|
2271
|
+
return null;
|
|
2272
|
+
}
|
|
2273
|
+
if (type === 2) {
|
|
2274
|
+
if (!state.d) {
|
|
2275
|
+
state.d = true;
|
|
2276
|
+
t[k] = [];
|
|
2277
|
+
}
|
|
2278
|
+
t[k].push(t = {});
|
|
2279
|
+
state.c[state.i++] = state = { t: 1, d: false, i: 0, c: {} };
|
|
2280
|
+
}
|
|
2281
|
+
if (state.d) {
|
|
2282
|
+
return null;
|
|
2283
|
+
}
|
|
2284
|
+
state.d = true;
|
|
2285
|
+
if (type === 1) {
|
|
2286
|
+
t = hasOwn ? t[k] : t[k] = {};
|
|
2287
|
+
} else if (type === 0 && hasOwn) {
|
|
2288
|
+
return null;
|
|
2289
|
+
}
|
|
2290
|
+
return [k, t, state.c];
|
|
2291
|
+
}
|
|
2292
|
+
function parse3(toml, { maxDepth = 1e3, integersAsBigInt } = {}) {
|
|
2293
|
+
let res = {};
|
|
2294
|
+
let meta = {};
|
|
2295
|
+
let tbl = res;
|
|
2296
|
+
let m = meta;
|
|
2297
|
+
for (let ptr = skipVoid(toml, 0); ptr < toml.length; ) {
|
|
2298
|
+
if (toml[ptr] === "[") {
|
|
2299
|
+
let isTableArray = toml[++ptr] === "[";
|
|
2300
|
+
let k = parseKey(toml, ptr += +isTableArray, "]");
|
|
2301
|
+
if (isTableArray) {
|
|
2302
|
+
if (toml[k[1] - 1] !== "]") {
|
|
2303
|
+
throw new TomlError("expected end of table declaration", {
|
|
2304
|
+
toml,
|
|
2305
|
+
ptr: k[1] - 1
|
|
2306
|
+
});
|
|
2307
|
+
}
|
|
2308
|
+
k[1]++;
|
|
2309
|
+
}
|
|
2310
|
+
let p = peekTable(
|
|
2311
|
+
k[0],
|
|
2312
|
+
res,
|
|
2313
|
+
meta,
|
|
2314
|
+
isTableArray ? 2 : 1
|
|
2315
|
+
/* Type.EXPLICIT */
|
|
2316
|
+
);
|
|
2317
|
+
if (!p) {
|
|
2318
|
+
throw new TomlError("trying to redefine an already defined table or value", {
|
|
2319
|
+
toml,
|
|
2320
|
+
ptr
|
|
2321
|
+
});
|
|
2322
|
+
}
|
|
2323
|
+
m = p[2];
|
|
2324
|
+
tbl = p[1];
|
|
2325
|
+
ptr = k[1];
|
|
2326
|
+
} else {
|
|
2327
|
+
let k = parseKey(toml, ptr);
|
|
2328
|
+
let p = peekTable(
|
|
2329
|
+
k[0],
|
|
2330
|
+
tbl,
|
|
2331
|
+
m,
|
|
2332
|
+
0
|
|
2333
|
+
/* Type.DOTTED */
|
|
2334
|
+
);
|
|
2335
|
+
if (!p) {
|
|
2336
|
+
throw new TomlError("trying to redefine an already defined table or value", {
|
|
2337
|
+
toml,
|
|
2338
|
+
ptr
|
|
2339
|
+
});
|
|
2340
|
+
}
|
|
2341
|
+
let v = extractValue(toml, k[1], void 0, maxDepth, integersAsBigInt);
|
|
2342
|
+
p[1][p[0]] = v[0];
|
|
2343
|
+
ptr = v[1];
|
|
2344
|
+
}
|
|
2345
|
+
ptr = skipVoid(toml, ptr, true);
|
|
2346
|
+
if (toml[ptr] && toml[ptr] !== "\n" && toml[ptr] !== "\r") {
|
|
2347
|
+
throw new TomlError("each key-value declaration must be followed by an end-of-line", {
|
|
2348
|
+
toml,
|
|
2349
|
+
ptr
|
|
2350
|
+
});
|
|
2351
|
+
}
|
|
2352
|
+
ptr = skipVoid(toml, ptr);
|
|
2353
|
+
}
|
|
2354
|
+
return res;
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
// scripts/permissions.ts
|
|
2358
|
+
var CODEX_SECTION = '[plugins."cadre@cadre".mcp_servers.cadre]';
|
|
2359
|
+
var CODEX_APPROVAL = 'default_tools_approval_mode = "approve"';
|
|
2360
|
+
var CLAUDE_APPROVAL = "mcp__cadre__*";
|
|
2361
|
+
var CLAUDE_SERVER_APPROVAL = "cadre";
|
|
2362
|
+
function isRecord(value) {
|
|
2363
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2364
|
+
}
|
|
2365
|
+
function atomicWrite(path, content) {
|
|
2366
|
+
const effectivePath = existsSync3(path) && lstatSync(path).isSymbolicLink() ? realpathSync(path) : path;
|
|
2367
|
+
const directory = dirname3(effectivePath);
|
|
2368
|
+
mkdirSync2(directory, { recursive: true });
|
|
2369
|
+
const temporary = `${directory}/.${basename(effectivePath)}.cadre-${process.pid}-${Date.now()}`;
|
|
2370
|
+
try {
|
|
2371
|
+
writeFileSync2(temporary, content, { encoding: "utf8", flag: "wx" });
|
|
2372
|
+
if (existsSync3(effectivePath)) chmodSync(temporary, statSync(effectivePath).mode);
|
|
2373
|
+
renameSync(temporary, effectivePath);
|
|
2374
|
+
} finally {
|
|
2375
|
+
if (existsSync3(temporary)) unlinkSync(temporary);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
function cadreCodexPolicy(value) {
|
|
2379
|
+
if (!isRecord(value)) return void 0;
|
|
2380
|
+
const plugins = value.plugins;
|
|
2381
|
+
if (!isRecord(plugins)) return void 0;
|
|
2382
|
+
const plugin = plugins["cadre@cadre"];
|
|
2383
|
+
if (!isRecord(plugin) || !isRecord(plugin.mcp_servers)) return void 0;
|
|
2384
|
+
const server = plugin.mcp_servers.cadre;
|
|
2385
|
+
return isRecord(server) ? server : void 0;
|
|
2386
|
+
}
|
|
2387
|
+
function configureCodexMcpApproval(configPath) {
|
|
2388
|
+
const existing = existsSync3(configPath) ? readFileSync3(configPath, "utf8") : "";
|
|
2389
|
+
let parsed;
|
|
2390
|
+
try {
|
|
2391
|
+
parsed = parse3(existing);
|
|
2392
|
+
} catch (error) {
|
|
2393
|
+
throw new Error(`Cannot update invalid Codex config ${configPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2394
|
+
}
|
|
2395
|
+
const currentPolicy = cadreCodexPolicy(parsed);
|
|
2396
|
+
if (currentPolicy?.default_tools_approval_mode === "approve") {
|
|
2397
|
+
return { path: configPath, changed: false, rule: CODEX_APPROVAL };
|
|
2398
|
+
}
|
|
2399
|
+
const headerPattern = /^[ \t]*\[plugins\."cadre@cadre"\.mcp_servers\.cadre\][ \t]*(?:#.*)?$/gm;
|
|
2400
|
+
const headers = [...existing.matchAll(headerPattern)];
|
|
2401
|
+
let proposed;
|
|
2402
|
+
if (currentPolicy) {
|
|
2403
|
+
if (headers.length !== 1) {
|
|
2404
|
+
throw new Error(
|
|
2405
|
+
`Cadre MCP policy already exists in ${configPath} using an unsupported TOML layout; set ${CODEX_APPROVAL} under ${CODEX_SECTION}`
|
|
2406
|
+
);
|
|
2407
|
+
}
|
|
2408
|
+
const header = headers[0];
|
|
2409
|
+
const sectionStart = header.index + header[0].length;
|
|
2410
|
+
const following = existing.slice(sectionStart);
|
|
2411
|
+
const nextSection = following.search(/^[ \t]*\[\[?.+$/m);
|
|
2412
|
+
const sectionEnd = nextSection === -1 ? existing.length : sectionStart + nextSection;
|
|
2413
|
+
const section = existing.slice(sectionStart, sectionEnd);
|
|
2414
|
+
const propertyPattern = /^[ \t]*default_tools_approval_mode[ \t]*=.*$/gm;
|
|
2415
|
+
const properties = [...section.matchAll(propertyPattern)];
|
|
2416
|
+
if (properties.length > 1) throw new Error(`${configPath}: duplicate Cadre MCP approval settings`);
|
|
2417
|
+
if (properties.length === 1) {
|
|
2418
|
+
const property = properties[0];
|
|
2419
|
+
const start = sectionStart + property.index;
|
|
2420
|
+
proposed = `${existing.slice(0, start)}${CODEX_APPROVAL}${existing.slice(start + property[0].length)}`;
|
|
2421
|
+
} else {
|
|
2422
|
+
proposed = `${existing.slice(0, sectionStart)}
|
|
2423
|
+
${CODEX_APPROVAL}${existing.slice(sectionStart)}`;
|
|
2424
|
+
}
|
|
2425
|
+
} else {
|
|
2426
|
+
if (headers.length) throw new Error(`${configPath}: Cadre MCP policy could not be parsed safely`);
|
|
2427
|
+
const prefix = existing.trimEnd();
|
|
2428
|
+
proposed = [
|
|
2429
|
+
prefix,
|
|
2430
|
+
prefix ? "" : null,
|
|
2431
|
+
"# Added by the Cadre plugin installer: pre-approve only Cadre MCP tools.",
|
|
2432
|
+
CODEX_SECTION,
|
|
2433
|
+
CODEX_APPROVAL
|
|
2434
|
+
].filter((line) => line !== null).join("\n") + "\n";
|
|
2435
|
+
}
|
|
2436
|
+
let verified;
|
|
2437
|
+
try {
|
|
2438
|
+
verified = parse3(proposed);
|
|
2439
|
+
} catch (error) {
|
|
2440
|
+
throw new Error(`Generated Codex config is invalid: ${error instanceof Error ? error.message : String(error)}`);
|
|
2441
|
+
}
|
|
2442
|
+
if (cadreCodexPolicy(verified)?.default_tools_approval_mode !== "approve") {
|
|
2443
|
+
throw new Error("Generated Codex config did not contain the Cadre MCP approval policy");
|
|
2444
|
+
}
|
|
2445
|
+
atomicWrite(configPath, proposed);
|
|
2446
|
+
return { path: configPath, changed: true, rule: CODEX_APPROVAL };
|
|
2447
|
+
}
|
|
2448
|
+
function stringArray(value) {
|
|
2449
|
+
return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
2450
|
+
}
|
|
2451
|
+
function assertStringArray(value, field, settingsPath) {
|
|
2452
|
+
if (value === void 0) return [];
|
|
2453
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string")) {
|
|
2454
|
+
throw new Error(`${settingsPath}: ${field} must be an array of strings`);
|
|
2455
|
+
}
|
|
2456
|
+
return value;
|
|
2457
|
+
}
|
|
2458
|
+
function deniesCadre(rule) {
|
|
2459
|
+
return rule === "mcp__*" || rule === "mcp__cadre" || rule.startsWith("mcp__cadre__");
|
|
2460
|
+
}
|
|
2461
|
+
function configureClaudeMcpApproval(settingsPath) {
|
|
2462
|
+
const existing = existsSync3(settingsPath) ? readFileSync3(settingsPath, "utf8") : "{}\n";
|
|
2463
|
+
const errors = [];
|
|
2464
|
+
const parsed = parse2(existing, errors, { allowTrailingComma: true });
|
|
2465
|
+
if (errors.length) {
|
|
2466
|
+
const detail = errors.map((error) => `${printParseErrorCode(error.error)} at ${error.offset}`).join(", ");
|
|
2467
|
+
throw new Error(`Cannot update invalid Claude settings ${settingsPath}: ${detail}`);
|
|
2468
|
+
}
|
|
2469
|
+
if (!isRecord(parsed)) throw new Error(`${settingsPath}: Claude settings root must be an object`);
|
|
2470
|
+
const root = isRecord(parsed) ? parsed : {};
|
|
2471
|
+
const permissions = isRecord(root.permissions) ? root.permissions : {};
|
|
2472
|
+
if (root.permissions !== void 0 && !isRecord(root.permissions)) {
|
|
2473
|
+
throw new Error(`${settingsPath}: permissions must be an object`);
|
|
2474
|
+
}
|
|
2475
|
+
const deny = assertStringArray(permissions.deny, "permissions.deny", settingsPath);
|
|
2476
|
+
const conflict = deny.find(deniesCadre);
|
|
2477
|
+
if (conflict) {
|
|
2478
|
+
throw new Error(`Claude deny rule ${JSON.stringify(conflict)} blocks Cadre MCP tools; remove it before installation`);
|
|
2479
|
+
}
|
|
2480
|
+
const allow = assertStringArray(permissions.allow, "permissions.allow", settingsPath);
|
|
2481
|
+
const enabledServers = assertStringArray(
|
|
2482
|
+
root.enabledMcpjsonServers,
|
|
2483
|
+
"enabledMcpjsonServers",
|
|
2484
|
+
settingsPath
|
|
2485
|
+
);
|
|
2486
|
+
const hasToolApproval = allow.includes(CLAUDE_APPROVAL);
|
|
2487
|
+
const hasServerApproval = enabledServers.includes(CLAUDE_SERVER_APPROVAL);
|
|
2488
|
+
if (hasToolApproval && hasServerApproval) {
|
|
2489
|
+
return { path: settingsPath, changed: false, rule: CLAUDE_APPROVAL };
|
|
2490
|
+
}
|
|
2491
|
+
const formattingOptions = { insertSpaces: true, tabSize: 2, eol: "\n" };
|
|
2492
|
+
let proposed = existing;
|
|
2493
|
+
if (!hasToolApproval) {
|
|
2494
|
+
proposed = applyEdits(proposed, modify(
|
|
2495
|
+
proposed,
|
|
2496
|
+
["permissions", "allow"],
|
|
2497
|
+
[...allow, CLAUDE_APPROVAL],
|
|
2498
|
+
{ formattingOptions }
|
|
2499
|
+
));
|
|
2500
|
+
}
|
|
2501
|
+
if (!hasServerApproval) {
|
|
2502
|
+
proposed = applyEdits(proposed, modify(
|
|
2503
|
+
proposed,
|
|
2504
|
+
["enabledMcpjsonServers"],
|
|
2505
|
+
[...enabledServers, CLAUDE_SERVER_APPROVAL],
|
|
2506
|
+
{ formattingOptions }
|
|
2507
|
+
));
|
|
2508
|
+
}
|
|
2509
|
+
const verificationErrors = [];
|
|
2510
|
+
const verified = parse2(proposed, verificationErrors, { allowTrailingComma: true });
|
|
2511
|
+
const verifiedPermissions = isRecord(verified) && isRecord(verified.permissions) ? verified.permissions : {};
|
|
2512
|
+
const verifiedServers = isRecord(verified) ? stringArray(verified.enabledMcpjsonServers) : [];
|
|
2513
|
+
if (verificationErrors.length || !stringArray(verifiedPermissions.allow).includes(CLAUDE_APPROVAL) || !verifiedServers.includes(CLAUDE_SERVER_APPROVAL)) {
|
|
2514
|
+
throw new Error("Generated Claude settings did not contain the Cadre MCP server and tool approval rules");
|
|
2515
|
+
}
|
|
2516
|
+
atomicWrite(settingsPath, proposed.endsWith("\n") ? proposed : `${proposed}
|
|
2517
|
+
`);
|
|
2518
|
+
return { path: settingsPath, changed: true, rule: CLAUDE_APPROVAL };
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
// scripts/install.ts
|
|
2522
|
+
var marketplaceName = "cadre";
|
|
2523
|
+
var pluginId = "cadre@cadre";
|
|
2524
|
+
function parseInstallOptions(args) {
|
|
2525
|
+
const options = {
|
|
2526
|
+
selection: "auto",
|
|
2527
|
+
marketplaceRoot: defaultMarketplaceRoot(),
|
|
2528
|
+
cachebuster: null,
|
|
2529
|
+
replaceMarketplace: false,
|
|
2530
|
+
promptMcpTools: false,
|
|
2531
|
+
prepareOnly: false,
|
|
2532
|
+
dryRun: false
|
|
2533
|
+
};
|
|
2534
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
2535
|
+
const arg = args[index];
|
|
2536
|
+
if (arg === "--agent" || arg === "--target") {
|
|
2537
|
+
options.selection = parseClient(optionValue(args, index, arg));
|
|
2538
|
+
index += 1;
|
|
2539
|
+
} else if (arg === "--marketplace-root") {
|
|
2540
|
+
options.marketplaceRoot = resolve4(optionValue(args, index, arg));
|
|
2541
|
+
index += 1;
|
|
2542
|
+
} else if (arg === "--home") {
|
|
2543
|
+
options.marketplaceRoot = marketplaceFromHome(optionValue(args, index, arg));
|
|
2544
|
+
index += 1;
|
|
2545
|
+
} else if (arg === "--cachebuster") {
|
|
2546
|
+
options.cachebuster = optionValue(args, index, arg);
|
|
2547
|
+
index += 1;
|
|
2548
|
+
} else if (arg === "--scope") {
|
|
2549
|
+
if (optionValue(args, index, arg) !== "user") throw new Error("Cadre plugin installation supports only --scope user");
|
|
2550
|
+
index += 1;
|
|
2551
|
+
} else if (arg === "--replace-marketplace" || arg === "--force") options.replaceMarketplace = true;
|
|
2552
|
+
else if (arg === "--prompt-mcp-tools") options.promptMcpTools = true;
|
|
2553
|
+
else if (arg === "--prepare-only") options.prepareOnly = true;
|
|
2554
|
+
else if (arg === "--dry-run") options.dryRun = true;
|
|
2555
|
+
else if (arg === "--yes" || arg === "-y") continue;
|
|
2556
|
+
else throw new Error(`Unknown install option: ${arg}`);
|
|
2557
|
+
}
|
|
2558
|
+
return options;
|
|
2559
|
+
}
|
|
2560
|
+
function selectedClients(selection) {
|
|
2561
|
+
if (selection === "all") return [...CLIENTS];
|
|
2562
|
+
if (selection !== "auto") return [selection];
|
|
2563
|
+
return CLIENTS.filter(commandExists);
|
|
2564
|
+
}
|
|
2565
|
+
function marketplacePath(entry) {
|
|
2566
|
+
return entry.root ?? entry.path ?? entry.installLocation ?? entry.marketplaceSource?.source ?? null;
|
|
2567
|
+
}
|
|
2568
|
+
function codexMarketplaces() {
|
|
2569
|
+
return runJson("codex", ["plugin", "marketplace", "list", "--json"]).marketplaces ?? [];
|
|
2570
|
+
}
|
|
2571
|
+
function claudeMarketplaces() {
|
|
2572
|
+
return runJson("claude", ["plugin", "marketplace", "list", "--json"]);
|
|
2573
|
+
}
|
|
2574
|
+
function replaceMarketplaceIfNeeded(client, existing, targetRoot, allowReplacement) {
|
|
2575
|
+
if (!existing) return false;
|
|
2576
|
+
const currentPath = marketplacePath(existing);
|
|
2577
|
+
if (currentPath && resolve4(currentPath) === targetRoot) return true;
|
|
2578
|
+
if (!allowReplacement) {
|
|
2579
|
+
throw new Error(
|
|
2580
|
+
`${client} already has a ${marketplaceName} marketplace at ${currentPath ?? "an unknown path"}; review it and rerun with --replace-marketplace`
|
|
2581
|
+
);
|
|
2582
|
+
}
|
|
2583
|
+
if (client === "codex") runCommand("codex", ["plugin", "marketplace", "remove", marketplaceName]);
|
|
2584
|
+
else runCommand("claude", ["plugin", "marketplace", "remove", marketplaceName]);
|
|
2585
|
+
return false;
|
|
2586
|
+
}
|
|
2587
|
+
function installCodex(targetRoot, allowReplacement, autoApproveMcp) {
|
|
2588
|
+
const existing = codexMarketplaces().find((entry) => entry.name === marketplaceName);
|
|
2589
|
+
const retained = replaceMarketplaceIfNeeded("codex", existing, targetRoot, allowReplacement);
|
|
2590
|
+
if (!retained) runCommand("codex", ["plugin", "marketplace", "add", targetRoot]);
|
|
2591
|
+
runCommand("codex", ["plugin", "add", pluginId]);
|
|
2592
|
+
const installed = runJson("codex", ["plugin", "list", "--json"]).installed ?? [];
|
|
2593
|
+
if (!installed.some((entry) => entry.pluginId === pluginId && entry.installed && entry.enabled)) {
|
|
2594
|
+
throw new Error(`Codex did not report ${pluginId} as installed and enabled`);
|
|
2595
|
+
}
|
|
2596
|
+
if (autoApproveMcp) {
|
|
2597
|
+
const codexRoot = process.env.CODEX_HOME ? resolve4(process.env.CODEX_HOME) : join4(homedir2(), ".codex");
|
|
2598
|
+
const update = configureCodexMcpApproval(join4(codexRoot, "config.toml"));
|
|
2599
|
+
process.stdout.write(`${update.changed ? "Added" : "Retained"} Codex Cadre MCP approval in ${update.path}
|
|
2600
|
+
`);
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
function installClaude(targetRoot, allowReplacement, autoApproveMcp) {
|
|
2604
|
+
const existing = claudeMarketplaces().find((entry) => entry.name === marketplaceName);
|
|
2605
|
+
const retained = replaceMarketplaceIfNeeded("claude", existing, targetRoot, allowReplacement);
|
|
2606
|
+
if (!retained) runCommand("claude", ["plugin", "marketplace", "add", targetRoot, "--scope", "user"]);
|
|
2607
|
+
else runCommand("claude", ["plugin", "marketplace", "update", marketplaceName]);
|
|
2608
|
+
const installed = runJson("claude", ["plugin", "list", "--json"]);
|
|
2609
|
+
if (installed.some((entry) => entry.id === pluginId && entry.scope === "user")) {
|
|
2610
|
+
runCommand("claude", ["plugin", "update", pluginId, "--scope", "user"]);
|
|
2611
|
+
} else {
|
|
2612
|
+
runCommand("claude", ["plugin", "install", pluginId, "--scope", "user"]);
|
|
2613
|
+
}
|
|
2614
|
+
const verified = runJson("claude", ["plugin", "list", "--json"]);
|
|
2615
|
+
if (!verified.some((entry) => entry.id === pluginId && entry.scope === "user" && entry.enabled)) {
|
|
2616
|
+
throw new Error(`Claude did not report ${pluginId} as installed and enabled`);
|
|
2617
|
+
}
|
|
2618
|
+
if (autoApproveMcp) {
|
|
2619
|
+
const claudeRoot = process.env.CLAUDE_HOME ?? process.env.CLAUDE_CONFIG_DIR ?? join4(homedir2(), ".claude");
|
|
2620
|
+
const update = configureClaudeMcpApproval(join4(resolve4(claudeRoot), "settings.json"));
|
|
2621
|
+
process.stdout.write(`${update.changed ? "Added" : "Retained"} Claude Cadre MCP approval in ${update.path}
|
|
2622
|
+
`);
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
function assertSafeTarget(targetRoot) {
|
|
2626
|
+
if (targetRoot === parse4(targetRoot).root || targetRoot === resolve4(homedir2())) {
|
|
2627
|
+
throw new Error(`refusing to use broad marketplace root ${targetRoot}`);
|
|
2628
|
+
}
|
|
2629
|
+
if (basename2(targetRoot) !== "cadre") throw new Error("marketplace root must end in a directory named cadre");
|
|
2630
|
+
}
|
|
2631
|
+
function prepareMarketplace(targetRoot, cachebuster) {
|
|
2632
|
+
const parent = dirname4(targetRoot);
|
|
2633
|
+
mkdirSync3(parent, { recursive: true });
|
|
2634
|
+
const stagingRoot = mkdtempSync(join4(parent, ".cadre-staging-"));
|
|
2635
|
+
const packaged = packagePluginMarketplace(stagingRoot, cachebuster ?? void 0);
|
|
2636
|
+
let backupRoot = null;
|
|
2637
|
+
if (existsSync4(targetRoot)) {
|
|
2638
|
+
const catalogs = [
|
|
2639
|
+
join4(targetRoot, ".agents", "plugins", "marketplace.json"),
|
|
2640
|
+
join4(targetRoot, ".claude-plugin", "marketplace.json")
|
|
2641
|
+
];
|
|
2642
|
+
const owned = catalogs.every((path) => existsSync4(path) && JSON.parse(readFileSync4(path, "utf8")).name === marketplaceName);
|
|
2643
|
+
if (!owned) throw new Error(`${targetRoot} exists but is not a Cadre dual-product marketplace`);
|
|
2644
|
+
backupRoot = `${targetRoot}.backup-${Date.now()}`;
|
|
2645
|
+
renameSync2(targetRoot, backupRoot);
|
|
2646
|
+
}
|
|
2647
|
+
renameSync2(packaged.targetRoot, targetRoot);
|
|
2648
|
+
return backupRoot;
|
|
2649
|
+
}
|
|
2650
|
+
function runInstall(args) {
|
|
2651
|
+
const options = parseInstallOptions(args);
|
|
2652
|
+
assertSafeTarget(options.marketplaceRoot);
|
|
2653
|
+
const clients = selectedClients(options.selection);
|
|
2654
|
+
if (!options.prepareOnly && clients.length === 0) {
|
|
2655
|
+
throw new Error("No supported client detected. Install Codex or Claude, or pass --target codex|claude|all");
|
|
2656
|
+
}
|
|
2657
|
+
for (const client of clients) {
|
|
2658
|
+
if (!commandExists(client) && !options.prepareOnly && !options.dryRun) {
|
|
2659
|
+
throw new Error(`${client} is not installed or not available on PATH`);
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
if (options.dryRun) {
|
|
2663
|
+
process.stdout.write(`Would prepare Cadre marketplace at ${options.marketplaceRoot}
|
|
2664
|
+
`);
|
|
2665
|
+
for (const client of clients) process.stdout.write(`Would install ${pluginId} for ${client} at user scope
|
|
2666
|
+
`);
|
|
2667
|
+
return 0;
|
|
2668
|
+
}
|
|
2669
|
+
const backupRoot = prepareMarketplace(options.marketplaceRoot, options.cachebuster);
|
|
2670
|
+
process.stdout.write(`Prepared Cadre plugin marketplace at ${options.marketplaceRoot}
|
|
2671
|
+
`);
|
|
2672
|
+
if (backupRoot) process.stdout.write(`Previous marketplace retained at ${backupRoot}
|
|
2673
|
+
`);
|
|
2674
|
+
if (options.prepareOnly) return 0;
|
|
2675
|
+
const autoApproveMcp = !options.promptMcpTools;
|
|
2676
|
+
for (const client of clients) {
|
|
2677
|
+
if (client === "codex") installCodex(options.marketplaceRoot, options.replaceMarketplace, autoApproveMcp);
|
|
2678
|
+
else installClaude(options.marketplaceRoot, options.replaceMarketplace, autoApproveMcp);
|
|
2679
|
+
}
|
|
2680
|
+
process.stdout.write(`Installed ${pluginId} for ${clients.join(" and ")}.
|
|
2681
|
+
`);
|
|
2682
|
+
process.stdout.write("Start a new Codex conversation and run /reload-plugins in Claude Code.\n");
|
|
2683
|
+
return 0;
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
// scripts/uninstall.ts
|
|
2687
|
+
import { existsSync as existsSync5, readFileSync as readFileSync5, readdirSync as readdirSync2, rmSync } from "node:fs";
|
|
2688
|
+
import { basename as basename3, dirname as dirname5, join as join5, resolve as resolve5 } from "node:path";
|
|
2689
|
+
var marketplaceName2 = "cadre";
|
|
2690
|
+
var pluginId2 = "cadre@cadre";
|
|
2691
|
+
function parseUninstallOptions(args) {
|
|
2692
|
+
const options = {
|
|
2693
|
+
selection: "all",
|
|
2694
|
+
marketplaceRoot: defaultMarketplaceRoot(),
|
|
2695
|
+
dryRun: false
|
|
2696
|
+
};
|
|
2697
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
2698
|
+
const arg = args[index];
|
|
2699
|
+
if (arg === "--agent" || arg === "--target") {
|
|
2700
|
+
options.selection = parseClient(optionValue(args, index, arg));
|
|
2701
|
+
index += 1;
|
|
2702
|
+
} else if (arg === "--marketplace-root") {
|
|
2703
|
+
options.marketplaceRoot = resolve5(optionValue(args, index, arg));
|
|
2704
|
+
index += 1;
|
|
2705
|
+
} else if (arg === "--home") {
|
|
2706
|
+
options.marketplaceRoot = marketplaceFromHome(optionValue(args, index, arg));
|
|
2707
|
+
index += 1;
|
|
2708
|
+
} else if (arg === "--scope") {
|
|
2709
|
+
if (optionValue(args, index, arg) !== "user") throw new Error("Cadre plugin uninstall supports only --scope user");
|
|
2710
|
+
index += 1;
|
|
2711
|
+
} else if (arg === "--dry-run") options.dryRun = true;
|
|
2712
|
+
else if (arg === "--yes" || arg === "-y") continue;
|
|
2713
|
+
else throw new Error(`Unknown uninstall option: ${arg}`);
|
|
2714
|
+
}
|
|
2715
|
+
return options;
|
|
2716
|
+
}
|
|
2717
|
+
function selectedClients2(selection) {
|
|
2718
|
+
if (selection === "all") return [...CLIENTS];
|
|
2719
|
+
if (selection === "auto") return CLIENTS.filter(commandExists);
|
|
2720
|
+
return [selection];
|
|
2721
|
+
}
|
|
2722
|
+
function ownedMarketplace(root) {
|
|
2723
|
+
if (!existsSync5(root)) return false;
|
|
2724
|
+
const catalogs = [
|
|
2725
|
+
join5(root, ".agents", "plugins", "marketplace.json"),
|
|
2726
|
+
join5(root, ".claude-plugin", "marketplace.json")
|
|
2727
|
+
];
|
|
2728
|
+
return catalogs.every((path) => {
|
|
2729
|
+
if (!existsSync5(path)) return false;
|
|
2730
|
+
try {
|
|
2731
|
+
return JSON.parse(readFileSync5(path, "utf8")).name === marketplaceName2;
|
|
2732
|
+
} catch {
|
|
2733
|
+
return false;
|
|
2734
|
+
}
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
function uninstallClient(client) {
|
|
2738
|
+
if (client === "codex") {
|
|
2739
|
+
runCommand("codex", ["plugin", "remove", pluginId2, "--json"]);
|
|
2740
|
+
runCommand("codex", ["plugin", "marketplace", "remove", marketplaceName2]);
|
|
2741
|
+
} else {
|
|
2742
|
+
runCommand("claude", ["plugin", "uninstall", "--scope", "user", "--yes", pluginId2]);
|
|
2743
|
+
runCommand("claude", ["plugin", "marketplace", "remove", "--scope", "user", marketplaceName2]);
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
function removeOwnedMarketplaces(root) {
|
|
2747
|
+
const removed = [];
|
|
2748
|
+
const candidates = [root];
|
|
2749
|
+
const parent = dirname5(root);
|
|
2750
|
+
const prefix = `${basename3(root)}.backup-`;
|
|
2751
|
+
if (existsSync5(parent)) {
|
|
2752
|
+
for (const entry of readdirSync2(parent)) {
|
|
2753
|
+
if (entry.startsWith(prefix)) candidates.push(join5(parent, entry));
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
for (const candidate of candidates) {
|
|
2757
|
+
if (!ownedMarketplace(candidate)) continue;
|
|
2758
|
+
rmSync(candidate, { recursive: true, force: true });
|
|
2759
|
+
removed.push(candidate);
|
|
2760
|
+
}
|
|
2761
|
+
return removed;
|
|
2762
|
+
}
|
|
2763
|
+
function runUninstall(args) {
|
|
2764
|
+
const options = parseUninstallOptions(args);
|
|
2765
|
+
const clients = selectedClients2(options.selection);
|
|
2766
|
+
if (options.dryRun) {
|
|
2767
|
+
for (const client of clients) process.stdout.write(`Would uninstall ${pluginId2} from ${client} at user scope
|
|
2768
|
+
`);
|
|
2769
|
+
if (options.selection === "all") process.stdout.write(`Would remove owned marketplace: ${options.marketplaceRoot}
|
|
2770
|
+
`);
|
|
2771
|
+
return 0;
|
|
2772
|
+
}
|
|
2773
|
+
let failed = false;
|
|
2774
|
+
for (const client of clients) {
|
|
2775
|
+
if (!commandExists(client)) {
|
|
2776
|
+
process.stderr.write(`${client} is not available; continuing local cleanup.
|
|
2777
|
+
`);
|
|
2778
|
+
continue;
|
|
2779
|
+
}
|
|
2780
|
+
try {
|
|
2781
|
+
uninstallClient(client);
|
|
2782
|
+
process.stdout.write(`Uninstalled ${pluginId2} from ${client}.
|
|
2783
|
+
`);
|
|
2784
|
+
} catch (error) {
|
|
2785
|
+
failed = true;
|
|
2786
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}; continuing local cleanup.
|
|
2787
|
+
`);
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
if (options.selection === "all") {
|
|
2791
|
+
const removed = removeOwnedMarketplaces(options.marketplaceRoot);
|
|
2792
|
+
if (removed.length) process.stdout.write(`Removed ${removed.join(", ")}
|
|
2793
|
+
`);
|
|
2794
|
+
else process.stdout.write("No owned Cadre marketplace files found to remove.\n");
|
|
2795
|
+
} else if (existsSync5(options.marketplaceRoot)) {
|
|
2796
|
+
process.stdout.write(`Retained shared marketplace at ${options.marketplaceRoot} for other clients.
|
|
2797
|
+
`);
|
|
2798
|
+
}
|
|
2799
|
+
return failed ? 1 : 0;
|
|
2800
|
+
}
|
|
2801
|
+
|
|
2802
|
+
// scripts/cli.ts
|
|
2803
|
+
function usage() {
|
|
2804
|
+
return [
|
|
2805
|
+
"Cadre CLI",
|
|
2806
|
+
"",
|
|
2807
|
+
"Usage:",
|
|
2808
|
+
" cadre-ai install [--target auto|codex|claude|all] [--scope user] [--dry-run] [--replace-marketplace]",
|
|
2809
|
+
" cadre-ai uninstall [--target codex|claude|all] [--scope user] [--dry-run]",
|
|
2810
|
+
" cadre-ai doctor",
|
|
2811
|
+
" cadre-ai --version",
|
|
2812
|
+
" cadre-ai help"
|
|
2813
|
+
].join("\n");
|
|
2814
|
+
}
|
|
2815
|
+
function packageRoot() {
|
|
2816
|
+
return resolve6(dirname6(fileURLToPath3(import.meta.url)), "..");
|
|
2817
|
+
}
|
|
2818
|
+
function runDoctor() {
|
|
2819
|
+
const root = packageRoot();
|
|
2820
|
+
const required = [
|
|
2821
|
+
"dist/cadre-cli.mjs",
|
|
2822
|
+
"dist/cadre-mcp.mjs",
|
|
2823
|
+
".codex-plugin/plugin.json",
|
|
2824
|
+
".claude-plugin/plugin.json",
|
|
2825
|
+
"skills",
|
|
2826
|
+
"templates"
|
|
2827
|
+
];
|
|
2828
|
+
const missing = required.filter((entry) => !existsSync6(join6(root, entry)));
|
|
2829
|
+
const packageJson = join6(root, "package.json");
|
|
2830
|
+
let identity = `cadre-ai@${CADRE_RUNTIME_VERSION}`;
|
|
2831
|
+
if (existsSync6(packageJson)) {
|
|
2832
|
+
const metadata = JSON.parse(readFileSync6(packageJson, "utf8"));
|
|
2833
|
+
identity = `${metadata.name ?? "cadre-ai"}@${metadata.version ?? CADRE_RUNTIME_VERSION}`;
|
|
2834
|
+
}
|
|
2835
|
+
process.stdout.write(`${identity}
|
|
2836
|
+
package root: ${root}
|
|
2837
|
+
`);
|
|
2838
|
+
if (missing.length) {
|
|
2839
|
+
process.stderr.write(`Missing packaged runtime assets: ${missing.join(", ")}
|
|
2840
|
+
`);
|
|
2841
|
+
return 1;
|
|
2842
|
+
}
|
|
2843
|
+
try {
|
|
2844
|
+
const templates = templateCatalog();
|
|
2845
|
+
process.stdout.write(`template catalog: ${templates.length}/${TEMPLATE_IDS.length} required templates
|
|
2846
|
+
`);
|
|
2847
|
+
} catch (error) {
|
|
2848
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}
|
|
2849
|
+
`);
|
|
2850
|
+
return 1;
|
|
2851
|
+
}
|
|
2852
|
+
process.stdout.write("self-contained runtime: ok\n");
|
|
2853
|
+
return 0;
|
|
2854
|
+
}
|
|
2855
|
+
function runCli(args) {
|
|
2856
|
+
const command = args[0] ?? "help";
|
|
2857
|
+
if (command === "install") return runInstall(args.slice(1));
|
|
2858
|
+
if (command === "uninstall" || command === "remove") return runUninstall(args.slice(1));
|
|
2859
|
+
if (command === "doctor") return runDoctor();
|
|
2860
|
+
if (command === "--version" || command === "-v" || command === "version") {
|
|
2861
|
+
process.stdout.write(`${CADRE_RUNTIME_VERSION}
|
|
2862
|
+
`);
|
|
2863
|
+
return 0;
|
|
2864
|
+
}
|
|
2865
|
+
if (command === "help" || command === "--help" || command === "-h") {
|
|
2866
|
+
process.stdout.write(`${usage()}
|
|
2867
|
+
`);
|
|
2868
|
+
return 0;
|
|
2869
|
+
}
|
|
2870
|
+
process.stderr.write(`${usage()}
|
|
2871
|
+
`);
|
|
2872
|
+
return 1;
|
|
2873
|
+
}
|
|
2874
|
+
try {
|
|
2875
|
+
process.exitCode = runCli(process.argv.slice(2));
|
|
2876
|
+
} catch (error) {
|
|
2877
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}
|
|
2878
|
+
`);
|
|
2879
|
+
process.exitCode = 1;
|
|
2880
|
+
}
|
|
2881
|
+
export {
|
|
2882
|
+
runCli
|
|
2883
|
+
};
|