@signetai/connector-opencode 0.147.21 → 0.147.22
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/dist/index.d.ts +8 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1594 -271
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { join as join4, relative } from "node:path";
|
|
|
5
5
|
|
|
6
6
|
// ../../../libs/connector-base/dist/index.js
|
|
7
7
|
import { randomBytes } from "node:crypto";
|
|
8
|
-
import { existsSync, readFileSync, renameSync, unlinkSync as unlinkSync2, writeFileSync } from "node:fs";
|
|
8
|
+
import { existsSync, readFileSync, renameSync, statSync, unlinkSync as unlinkSync2, writeFileSync } from "node:fs";
|
|
9
9
|
import { dirname as dirname2, join as join3, resolve } from "node:path";
|
|
10
10
|
import { createRequire } from "node:module";
|
|
11
11
|
import { dirname, join } from "node:path";
|
|
@@ -10999,12 +10999,16 @@ function isSignetGeneratedFile(raw) {
|
|
|
10999
10999
|
`).slice(0, 6);
|
|
11000
11000
|
return lines.some((line, i) => /^#\s+AUTO-GENERATED\s+from\s+.*\s+by\s+Signet/i.test(line) || /^#\s+Auto-generated\s+from\s+/.test(line) && i + 1 < lines.length && /^#\s+Source:\s+/.test(lines[i + 1]));
|
|
11001
11001
|
}
|
|
11002
|
-
function
|
|
11003
|
-
const content = `${JSON.stringify(data, null, indent)}
|
|
11004
|
-
`;
|
|
11002
|
+
function atomicWriteText(path, content, mode) {
|
|
11005
11003
|
const tmp = join3(dirname2(path), `.${randomBytes(6).toString("hex")}.tmp`);
|
|
11004
|
+
let writeMode = mode;
|
|
11005
|
+
if (writeMode === undefined) {
|
|
11006
|
+
try {
|
|
11007
|
+
writeMode = statSync(path).mode & 511;
|
|
11008
|
+
} catch {}
|
|
11009
|
+
}
|
|
11006
11010
|
try {
|
|
11007
|
-
writeFileSync(tmp, content, "utf-8");
|
|
11011
|
+
writeFileSync(tmp, content, { encoding: "utf-8", mode: writeMode });
|
|
11008
11012
|
renameSync(tmp, path);
|
|
11009
11013
|
} catch (err) {
|
|
11010
11014
|
try {
|
|
@@ -11013,6 +11017,10 @@ function atomicWriteJson(path, data, indent = 2) {
|
|
|
11013
11017
|
throw err;
|
|
11014
11018
|
}
|
|
11015
11019
|
}
|
|
11020
|
+
function atomicWriteJson(path, data, indent = 2) {
|
|
11021
|
+
atomicWriteText(path, `${JSON.stringify(data, null, indent)}
|
|
11022
|
+
`);
|
|
11023
|
+
}
|
|
11016
11024
|
|
|
11017
11025
|
// ../../../platform/core/dist/index.js
|
|
11018
11026
|
import { createRequire as createRequire3 } from "node:module";
|
|
@@ -21624,6 +21632,77 @@ function parseSimpleYaml(text) {
|
|
|
21624
21632
|
return {};
|
|
21625
21633
|
}
|
|
21626
21634
|
}
|
|
21635
|
+
function readEnv(env, name) {
|
|
21636
|
+
const value = env[name];
|
|
21637
|
+
if (typeof value !== "string")
|
|
21638
|
+
return;
|
|
21639
|
+
const trimmed = value.trim();
|
|
21640
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
21641
|
+
}
|
|
21642
|
+
function normalizePort(raw, fallback) {
|
|
21643
|
+
if (!raw)
|
|
21644
|
+
return String(fallback);
|
|
21645
|
+
if (!/^\d+$/.test(raw)) {
|
|
21646
|
+
throw new Error(`SIGNET_PORT must be an integer between 1 and 65535: ${raw}`);
|
|
21647
|
+
}
|
|
21648
|
+
const port = Number.parseInt(raw, 10);
|
|
21649
|
+
if (!Number.isFinite(port) || port < 1 || port > 65535) {
|
|
21650
|
+
throw new Error(`SIGNET_PORT must be an integer between 1 and 65535: ${raw}`);
|
|
21651
|
+
}
|
|
21652
|
+
return String(port);
|
|
21653
|
+
}
|
|
21654
|
+
function bracketIpv6Host(host) {
|
|
21655
|
+
if (host.startsWith("[") || !host.includes(":"))
|
|
21656
|
+
return host;
|
|
21657
|
+
return `[${host}]`;
|
|
21658
|
+
}
|
|
21659
|
+
function assertPlainHost(raw) {
|
|
21660
|
+
if (raw.includes("/") || raw.includes("@") || raw.includes("?") || raw.includes("#")) {
|
|
21661
|
+
throw new Error(`SIGNET_HOST must be a hostname or IP address, not a URL: ${raw}`);
|
|
21662
|
+
}
|
|
21663
|
+
const host = raw.startsWith("[") && raw.endsWith("]") ? raw.slice(1, -1) : raw;
|
|
21664
|
+
if (host.includes(":")) {
|
|
21665
|
+
if (/^[0-9A-Fa-f:.]+$/.test(host))
|
|
21666
|
+
return;
|
|
21667
|
+
throw new Error(`SIGNET_HOST must be a hostname or IP address: ${raw}`);
|
|
21668
|
+
}
|
|
21669
|
+
if (!/^[A-Za-z0-9]([A-Za-z0-9.-]*[A-Za-z0-9])?$/.test(host)) {
|
|
21670
|
+
throw new Error(`SIGNET_HOST must be a hostname or IP address: ${raw}`);
|
|
21671
|
+
}
|
|
21672
|
+
}
|
|
21673
|
+
function normalizeDaemonUrl(raw, source) {
|
|
21674
|
+
let parsed;
|
|
21675
|
+
try {
|
|
21676
|
+
parsed = new URL(raw);
|
|
21677
|
+
} catch {
|
|
21678
|
+
throw new Error(`${source} must be an http(s) URL: ${raw}`);
|
|
21679
|
+
}
|
|
21680
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
21681
|
+
throw new Error(`${source} must use http or https: ${raw}`);
|
|
21682
|
+
}
|
|
21683
|
+
if (parsed.username || parsed.password) {
|
|
21684
|
+
throw new Error(`${source} must not include username or password credentials`);
|
|
21685
|
+
}
|
|
21686
|
+
if (parsed.search || parsed.hash) {
|
|
21687
|
+
throw new Error(`${source} must not include query strings or fragments`);
|
|
21688
|
+
}
|
|
21689
|
+
if (parsed.pathname !== "/" && parsed.pathname !== "") {
|
|
21690
|
+
throw new Error(`${source} must point at the daemon origin, not a path: ${raw}`);
|
|
21691
|
+
}
|
|
21692
|
+
return parsed.toString().replace(/\/$/, "");
|
|
21693
|
+
}
|
|
21694
|
+
function resolveSignetDaemonUrl(opts = {}) {
|
|
21695
|
+
const env = opts.env ?? process.env;
|
|
21696
|
+
const fallbackHost = opts.defaultHost ?? "127.0.0.1";
|
|
21697
|
+
const fallbackPort = opts.defaultPort ?? 3850;
|
|
21698
|
+
const explicit = readEnv(env, "SIGNET_DAEMON_URL");
|
|
21699
|
+
if (explicit)
|
|
21700
|
+
return normalizeDaemonUrl(explicit, "SIGNET_DAEMON_URL");
|
|
21701
|
+
const host = readEnv(env, "SIGNET_HOST") ?? fallbackHost;
|
|
21702
|
+
assertPlainHost(host);
|
|
21703
|
+
const port = normalizePort(readEnv(env, "SIGNET_PORT"), fallbackPort);
|
|
21704
|
+
return normalizeDaemonUrl(`http://${bracketIpv6Host(host)}:${port}`, "SIGNET_HOST/SIGNET_PORT");
|
|
21705
|
+
}
|
|
21627
21706
|
var native2 = null;
|
|
21628
21707
|
try {
|
|
21629
21708
|
const esmRequire = createRequire22(import.meta.url);
|
|
@@ -21920,6 +21999,1329 @@ var CODE_EXTS2 = new Set([
|
|
|
21920
21999
|
]);
|
|
21921
22000
|
var SKIP_FILES2 = new Set([".DS_Store", "Thumbs.db", ".gitkeep", "node_modules", ".git", ".env", ".env.local"]);
|
|
21922
22001
|
|
|
22002
|
+
// ../../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
22003
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
22004
|
+
const len = text.length;
|
|
22005
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
22006
|
+
function scanHexDigits(count, exact) {
|
|
22007
|
+
let digits = 0;
|
|
22008
|
+
let value2 = 0;
|
|
22009
|
+
while (digits < count || !exact) {
|
|
22010
|
+
let ch = text.charCodeAt(pos);
|
|
22011
|
+
if (ch >= 48 && ch <= 57) {
|
|
22012
|
+
value2 = value2 * 16 + ch - 48;
|
|
22013
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
22014
|
+
value2 = value2 * 16 + ch - 65 + 10;
|
|
22015
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
22016
|
+
value2 = value2 * 16 + ch - 97 + 10;
|
|
22017
|
+
} else {
|
|
22018
|
+
break;
|
|
22019
|
+
}
|
|
22020
|
+
pos++;
|
|
22021
|
+
digits++;
|
|
22022
|
+
}
|
|
22023
|
+
if (digits < count) {
|
|
22024
|
+
value2 = -1;
|
|
22025
|
+
}
|
|
22026
|
+
return value2;
|
|
22027
|
+
}
|
|
22028
|
+
function setPosition(newPosition) {
|
|
22029
|
+
pos = newPosition;
|
|
22030
|
+
value = "";
|
|
22031
|
+
tokenOffset = 0;
|
|
22032
|
+
token = 16;
|
|
22033
|
+
scanError = 0;
|
|
22034
|
+
}
|
|
22035
|
+
function scanNumber() {
|
|
22036
|
+
let start = pos;
|
|
22037
|
+
if (text.charCodeAt(pos) === 48) {
|
|
22038
|
+
pos++;
|
|
22039
|
+
} else {
|
|
22040
|
+
pos++;
|
|
22041
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
22042
|
+
pos++;
|
|
22043
|
+
}
|
|
22044
|
+
}
|
|
22045
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
22046
|
+
pos++;
|
|
22047
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
22048
|
+
pos++;
|
|
22049
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
22050
|
+
pos++;
|
|
22051
|
+
}
|
|
22052
|
+
} else {
|
|
22053
|
+
scanError = 3;
|
|
22054
|
+
return text.substring(start, pos);
|
|
22055
|
+
}
|
|
22056
|
+
}
|
|
22057
|
+
let end = pos;
|
|
22058
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
22059
|
+
pos++;
|
|
22060
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
22061
|
+
pos++;
|
|
22062
|
+
}
|
|
22063
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
22064
|
+
pos++;
|
|
22065
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
22066
|
+
pos++;
|
|
22067
|
+
}
|
|
22068
|
+
end = pos;
|
|
22069
|
+
} else {
|
|
22070
|
+
scanError = 3;
|
|
22071
|
+
}
|
|
22072
|
+
}
|
|
22073
|
+
return text.substring(start, end);
|
|
22074
|
+
}
|
|
22075
|
+
function scanString() {
|
|
22076
|
+
let result = "", start = pos;
|
|
22077
|
+
while (true) {
|
|
22078
|
+
if (pos >= len) {
|
|
22079
|
+
result += text.substring(start, pos);
|
|
22080
|
+
scanError = 2;
|
|
22081
|
+
break;
|
|
22082
|
+
}
|
|
22083
|
+
const ch = text.charCodeAt(pos);
|
|
22084
|
+
if (ch === 34) {
|
|
22085
|
+
result += text.substring(start, pos);
|
|
22086
|
+
pos++;
|
|
22087
|
+
break;
|
|
22088
|
+
}
|
|
22089
|
+
if (ch === 92) {
|
|
22090
|
+
result += text.substring(start, pos);
|
|
22091
|
+
pos++;
|
|
22092
|
+
if (pos >= len) {
|
|
22093
|
+
scanError = 2;
|
|
22094
|
+
break;
|
|
22095
|
+
}
|
|
22096
|
+
const ch2 = text.charCodeAt(pos++);
|
|
22097
|
+
switch (ch2) {
|
|
22098
|
+
case 34:
|
|
22099
|
+
result += '"';
|
|
22100
|
+
break;
|
|
22101
|
+
case 92:
|
|
22102
|
+
result += "\\";
|
|
22103
|
+
break;
|
|
22104
|
+
case 47:
|
|
22105
|
+
result += "/";
|
|
22106
|
+
break;
|
|
22107
|
+
case 98:
|
|
22108
|
+
result += "\b";
|
|
22109
|
+
break;
|
|
22110
|
+
case 102:
|
|
22111
|
+
result += "\f";
|
|
22112
|
+
break;
|
|
22113
|
+
case 110:
|
|
22114
|
+
result += `
|
|
22115
|
+
`;
|
|
22116
|
+
break;
|
|
22117
|
+
case 114:
|
|
22118
|
+
result += "\r";
|
|
22119
|
+
break;
|
|
22120
|
+
case 116:
|
|
22121
|
+
result += "\t";
|
|
22122
|
+
break;
|
|
22123
|
+
case 117:
|
|
22124
|
+
const ch3 = scanHexDigits(4, true);
|
|
22125
|
+
if (ch3 >= 0) {
|
|
22126
|
+
result += String.fromCharCode(ch3);
|
|
22127
|
+
} else {
|
|
22128
|
+
scanError = 4;
|
|
22129
|
+
}
|
|
22130
|
+
break;
|
|
22131
|
+
default:
|
|
22132
|
+
scanError = 5;
|
|
22133
|
+
}
|
|
22134
|
+
start = pos;
|
|
22135
|
+
continue;
|
|
22136
|
+
}
|
|
22137
|
+
if (ch >= 0 && ch <= 31) {
|
|
22138
|
+
if (isLineBreak(ch)) {
|
|
22139
|
+
result += text.substring(start, pos);
|
|
22140
|
+
scanError = 2;
|
|
22141
|
+
break;
|
|
22142
|
+
} else {
|
|
22143
|
+
scanError = 6;
|
|
22144
|
+
}
|
|
22145
|
+
}
|
|
22146
|
+
pos++;
|
|
22147
|
+
}
|
|
22148
|
+
return result;
|
|
22149
|
+
}
|
|
22150
|
+
function scanNext() {
|
|
22151
|
+
value = "";
|
|
22152
|
+
scanError = 0;
|
|
22153
|
+
tokenOffset = pos;
|
|
22154
|
+
lineStartOffset = lineNumber;
|
|
22155
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
22156
|
+
if (pos >= len) {
|
|
22157
|
+
tokenOffset = len;
|
|
22158
|
+
return token = 17;
|
|
22159
|
+
}
|
|
22160
|
+
let code = text.charCodeAt(pos);
|
|
22161
|
+
if (isWhiteSpace(code)) {
|
|
22162
|
+
do {
|
|
22163
|
+
pos++;
|
|
22164
|
+
value += String.fromCharCode(code);
|
|
22165
|
+
code = text.charCodeAt(pos);
|
|
22166
|
+
} while (isWhiteSpace(code));
|
|
22167
|
+
return token = 15;
|
|
22168
|
+
}
|
|
22169
|
+
if (isLineBreak(code)) {
|
|
22170
|
+
pos++;
|
|
22171
|
+
value += String.fromCharCode(code);
|
|
22172
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
22173
|
+
pos++;
|
|
22174
|
+
value += `
|
|
22175
|
+
`;
|
|
22176
|
+
}
|
|
22177
|
+
lineNumber++;
|
|
22178
|
+
tokenLineStartOffset = pos;
|
|
22179
|
+
return token = 14;
|
|
22180
|
+
}
|
|
22181
|
+
switch (code) {
|
|
22182
|
+
case 123:
|
|
22183
|
+
pos++;
|
|
22184
|
+
return token = 1;
|
|
22185
|
+
case 125:
|
|
22186
|
+
pos++;
|
|
22187
|
+
return token = 2;
|
|
22188
|
+
case 91:
|
|
22189
|
+
pos++;
|
|
22190
|
+
return token = 3;
|
|
22191
|
+
case 93:
|
|
22192
|
+
pos++;
|
|
22193
|
+
return token = 4;
|
|
22194
|
+
case 58:
|
|
22195
|
+
pos++;
|
|
22196
|
+
return token = 6;
|
|
22197
|
+
case 44:
|
|
22198
|
+
pos++;
|
|
22199
|
+
return token = 5;
|
|
22200
|
+
case 34:
|
|
22201
|
+
pos++;
|
|
22202
|
+
value = scanString();
|
|
22203
|
+
return token = 10;
|
|
22204
|
+
case 47:
|
|
22205
|
+
const start = pos - 1;
|
|
22206
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
22207
|
+
pos += 2;
|
|
22208
|
+
while (pos < len) {
|
|
22209
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
22210
|
+
break;
|
|
22211
|
+
}
|
|
22212
|
+
pos++;
|
|
22213
|
+
}
|
|
22214
|
+
value = text.substring(start, pos);
|
|
22215
|
+
return token = 12;
|
|
22216
|
+
}
|
|
22217
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
22218
|
+
pos += 2;
|
|
22219
|
+
const safeLength = len - 1;
|
|
22220
|
+
let commentClosed = false;
|
|
22221
|
+
while (pos < safeLength) {
|
|
22222
|
+
const ch = text.charCodeAt(pos);
|
|
22223
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
22224
|
+
pos += 2;
|
|
22225
|
+
commentClosed = true;
|
|
22226
|
+
break;
|
|
22227
|
+
}
|
|
22228
|
+
pos++;
|
|
22229
|
+
if (isLineBreak(ch)) {
|
|
22230
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
22231
|
+
pos++;
|
|
22232
|
+
}
|
|
22233
|
+
lineNumber++;
|
|
22234
|
+
tokenLineStartOffset = pos;
|
|
22235
|
+
}
|
|
22236
|
+
}
|
|
22237
|
+
if (!commentClosed) {
|
|
22238
|
+
pos++;
|
|
22239
|
+
scanError = 1;
|
|
22240
|
+
}
|
|
22241
|
+
value = text.substring(start, pos);
|
|
22242
|
+
return token = 13;
|
|
22243
|
+
}
|
|
22244
|
+
value += String.fromCharCode(code);
|
|
22245
|
+
pos++;
|
|
22246
|
+
return token = 16;
|
|
22247
|
+
case 45:
|
|
22248
|
+
value += String.fromCharCode(code);
|
|
22249
|
+
pos++;
|
|
22250
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
22251
|
+
return token = 16;
|
|
22252
|
+
}
|
|
22253
|
+
case 48:
|
|
22254
|
+
case 49:
|
|
22255
|
+
case 50:
|
|
22256
|
+
case 51:
|
|
22257
|
+
case 52:
|
|
22258
|
+
case 53:
|
|
22259
|
+
case 54:
|
|
22260
|
+
case 55:
|
|
22261
|
+
case 56:
|
|
22262
|
+
case 57:
|
|
22263
|
+
value += scanNumber();
|
|
22264
|
+
return token = 11;
|
|
22265
|
+
default:
|
|
22266
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
22267
|
+
pos++;
|
|
22268
|
+
code = text.charCodeAt(pos);
|
|
22269
|
+
}
|
|
22270
|
+
if (tokenOffset !== pos) {
|
|
22271
|
+
value = text.substring(tokenOffset, pos);
|
|
22272
|
+
switch (value) {
|
|
22273
|
+
case "true":
|
|
22274
|
+
return token = 8;
|
|
22275
|
+
case "false":
|
|
22276
|
+
return token = 9;
|
|
22277
|
+
case "null":
|
|
22278
|
+
return token = 7;
|
|
22279
|
+
}
|
|
22280
|
+
return token = 16;
|
|
22281
|
+
}
|
|
22282
|
+
value += String.fromCharCode(code);
|
|
22283
|
+
pos++;
|
|
22284
|
+
return token = 16;
|
|
22285
|
+
}
|
|
22286
|
+
}
|
|
22287
|
+
function isUnknownContentCharacter(code) {
|
|
22288
|
+
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
22289
|
+
return false;
|
|
22290
|
+
}
|
|
22291
|
+
switch (code) {
|
|
22292
|
+
case 125:
|
|
22293
|
+
case 93:
|
|
22294
|
+
case 123:
|
|
22295
|
+
case 91:
|
|
22296
|
+
case 34:
|
|
22297
|
+
case 58:
|
|
22298
|
+
case 44:
|
|
22299
|
+
case 47:
|
|
22300
|
+
return false;
|
|
22301
|
+
}
|
|
22302
|
+
return true;
|
|
22303
|
+
}
|
|
22304
|
+
function scanNextNonTrivia() {
|
|
22305
|
+
let result;
|
|
22306
|
+
do {
|
|
22307
|
+
result = scanNext();
|
|
22308
|
+
} while (result >= 12 && result <= 15);
|
|
22309
|
+
return result;
|
|
22310
|
+
}
|
|
22311
|
+
return {
|
|
22312
|
+
setPosition,
|
|
22313
|
+
getPosition: () => pos,
|
|
22314
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
22315
|
+
getToken: () => token,
|
|
22316
|
+
getTokenValue: () => value,
|
|
22317
|
+
getTokenOffset: () => tokenOffset,
|
|
22318
|
+
getTokenLength: () => pos - tokenOffset,
|
|
22319
|
+
getTokenStartLine: () => lineStartOffset,
|
|
22320
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
22321
|
+
getTokenError: () => scanError
|
|
22322
|
+
};
|
|
22323
|
+
}
|
|
22324
|
+
function isWhiteSpace(ch) {
|
|
22325
|
+
return ch === 32 || ch === 9;
|
|
22326
|
+
}
|
|
22327
|
+
function isLineBreak(ch) {
|
|
22328
|
+
return ch === 10 || ch === 13;
|
|
22329
|
+
}
|
|
22330
|
+
function isDigit(ch) {
|
|
22331
|
+
return ch >= 48 && ch <= 57;
|
|
22332
|
+
}
|
|
22333
|
+
var CharacterCodes;
|
|
22334
|
+
(function(CharacterCodes2) {
|
|
22335
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
22336
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
22337
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
22338
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
22339
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
22340
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
22341
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
22342
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
22343
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
22344
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
22345
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
22346
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
22347
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
22348
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
22349
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
22350
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
22351
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
22352
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
22353
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
22354
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
22355
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
22356
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
22357
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
22358
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
22359
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
22360
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
22361
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
22362
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
22363
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
22364
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
22365
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
22366
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
22367
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
22368
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
22369
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
22370
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
22371
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
22372
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
22373
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
22374
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
22375
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
22376
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
22377
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
22378
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
22379
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
22380
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
22381
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
22382
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
22383
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
22384
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
22385
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
22386
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
22387
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
22388
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
22389
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
22390
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
22391
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
22392
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
22393
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
22394
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
22395
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
22396
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
22397
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
22398
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
22399
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
22400
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
22401
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
22402
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
22403
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
22404
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
22405
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
22406
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
22407
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
22408
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
22409
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
22410
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
22411
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
22412
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
22413
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
22414
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
22415
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
22416
|
+
|
|
22417
|
+
// ../../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
22418
|
+
var cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
22419
|
+
return " ".repeat(index);
|
|
22420
|
+
});
|
|
22421
|
+
var maxCachedValues = 200;
|
|
22422
|
+
var cachedBreakLinesWithSpaces = {
|
|
22423
|
+
" ": {
|
|
22424
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
22425
|
+
return `
|
|
22426
|
+
` + " ".repeat(index);
|
|
22427
|
+
}),
|
|
22428
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
22429
|
+
return "\r" + " ".repeat(index);
|
|
22430
|
+
}),
|
|
22431
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
22432
|
+
return `\r
|
|
22433
|
+
` + " ".repeat(index);
|
|
22434
|
+
})
|
|
22435
|
+
},
|
|
22436
|
+
"\t": {
|
|
22437
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
22438
|
+
return `
|
|
22439
|
+
` + "\t".repeat(index);
|
|
22440
|
+
}),
|
|
22441
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
22442
|
+
return "\r" + "\t".repeat(index);
|
|
22443
|
+
}),
|
|
22444
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
22445
|
+
return `\r
|
|
22446
|
+
` + "\t".repeat(index);
|
|
22447
|
+
})
|
|
22448
|
+
}
|
|
22449
|
+
};
|
|
22450
|
+
var supportedEols = [`
|
|
22451
|
+
`, "\r", `\r
|
|
22452
|
+
`];
|
|
22453
|
+
|
|
22454
|
+
// ../../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/format.js
|
|
22455
|
+
function format(documentText, range, options) {
|
|
22456
|
+
let initialIndentLevel;
|
|
22457
|
+
let formatText;
|
|
22458
|
+
let formatTextStart;
|
|
22459
|
+
let rangeStart;
|
|
22460
|
+
let rangeEnd;
|
|
22461
|
+
if (range) {
|
|
22462
|
+
rangeStart = range.offset;
|
|
22463
|
+
rangeEnd = rangeStart + range.length;
|
|
22464
|
+
formatTextStart = rangeStart;
|
|
22465
|
+
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
|
|
22466
|
+
formatTextStart--;
|
|
22467
|
+
}
|
|
22468
|
+
let endOffset = rangeEnd;
|
|
22469
|
+
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
|
|
22470
|
+
endOffset++;
|
|
22471
|
+
}
|
|
22472
|
+
formatText = documentText.substring(formatTextStart, endOffset);
|
|
22473
|
+
initialIndentLevel = computeIndentLevel(formatText, options);
|
|
22474
|
+
} else {
|
|
22475
|
+
formatText = documentText;
|
|
22476
|
+
initialIndentLevel = 0;
|
|
22477
|
+
formatTextStart = 0;
|
|
22478
|
+
rangeStart = 0;
|
|
22479
|
+
rangeEnd = documentText.length;
|
|
22480
|
+
}
|
|
22481
|
+
const eol = getEOL(options, documentText);
|
|
22482
|
+
const eolFastPathSupported = supportedEols.includes(eol);
|
|
22483
|
+
let numberLineBreaks = 0;
|
|
22484
|
+
let indentLevel = 0;
|
|
22485
|
+
let indentValue;
|
|
22486
|
+
if (options.insertSpaces) {
|
|
22487
|
+
indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
|
|
22488
|
+
} else {
|
|
22489
|
+
indentValue = "\t";
|
|
22490
|
+
}
|
|
22491
|
+
const indentType = indentValue === "\t" ? "\t" : " ";
|
|
22492
|
+
let scanner = createScanner(formatText, false);
|
|
22493
|
+
let hasError = false;
|
|
22494
|
+
function newLinesAndIndent() {
|
|
22495
|
+
if (numberLineBreaks > 1) {
|
|
22496
|
+
return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
22497
|
+
}
|
|
22498
|
+
const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
|
|
22499
|
+
if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
|
|
22500
|
+
return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
22501
|
+
}
|
|
22502
|
+
if (amountOfSpaces <= 0) {
|
|
22503
|
+
return eol;
|
|
22504
|
+
}
|
|
22505
|
+
return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
|
|
22506
|
+
}
|
|
22507
|
+
function scanNext() {
|
|
22508
|
+
let token = scanner.scan();
|
|
22509
|
+
numberLineBreaks = 0;
|
|
22510
|
+
while (token === 15 || token === 14) {
|
|
22511
|
+
if (token === 14 && options.keepLines) {
|
|
22512
|
+
numberLineBreaks += 1;
|
|
22513
|
+
} else if (token === 14) {
|
|
22514
|
+
numberLineBreaks = 1;
|
|
22515
|
+
}
|
|
22516
|
+
token = scanner.scan();
|
|
22517
|
+
}
|
|
22518
|
+
hasError = token === 16 || scanner.getTokenError() !== 0;
|
|
22519
|
+
return token;
|
|
22520
|
+
}
|
|
22521
|
+
const editOperations = [];
|
|
22522
|
+
function addEdit(text, startOffset, endOffset) {
|
|
22523
|
+
if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) {
|
|
22524
|
+
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
|
|
22525
|
+
}
|
|
22526
|
+
}
|
|
22527
|
+
let firstToken = scanNext();
|
|
22528
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
22529
|
+
addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
22530
|
+
}
|
|
22531
|
+
if (firstToken !== 17) {
|
|
22532
|
+
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
22533
|
+
let initialIndent = indentValue.length * initialIndentLevel < 20 && options.insertSpaces ? cachedSpaces[indentValue.length * initialIndentLevel] : repeat(indentValue, initialIndentLevel);
|
|
22534
|
+
addEdit(initialIndent, formatTextStart, firstTokenStart);
|
|
22535
|
+
}
|
|
22536
|
+
while (firstToken !== 17) {
|
|
22537
|
+
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
22538
|
+
let secondToken = scanNext();
|
|
22539
|
+
let replaceContent = "";
|
|
22540
|
+
let needsLineBreak = false;
|
|
22541
|
+
while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
|
|
22542
|
+
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
22543
|
+
addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
|
|
22544
|
+
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
22545
|
+
needsLineBreak = secondToken === 12;
|
|
22546
|
+
replaceContent = needsLineBreak ? newLinesAndIndent() : "";
|
|
22547
|
+
secondToken = scanNext();
|
|
22548
|
+
}
|
|
22549
|
+
if (secondToken === 2) {
|
|
22550
|
+
if (firstToken !== 1) {
|
|
22551
|
+
indentLevel--;
|
|
22552
|
+
}
|
|
22553
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) {
|
|
22554
|
+
replaceContent = newLinesAndIndent();
|
|
22555
|
+
} else if (options.keepLines) {
|
|
22556
|
+
replaceContent = cachedSpaces[1];
|
|
22557
|
+
}
|
|
22558
|
+
} else if (secondToken === 4) {
|
|
22559
|
+
if (firstToken !== 3) {
|
|
22560
|
+
indentLevel--;
|
|
22561
|
+
}
|
|
22562
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) {
|
|
22563
|
+
replaceContent = newLinesAndIndent();
|
|
22564
|
+
} else if (options.keepLines) {
|
|
22565
|
+
replaceContent = cachedSpaces[1];
|
|
22566
|
+
}
|
|
22567
|
+
} else {
|
|
22568
|
+
switch (firstToken) {
|
|
22569
|
+
case 3:
|
|
22570
|
+
case 1:
|
|
22571
|
+
indentLevel++;
|
|
22572
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
22573
|
+
replaceContent = newLinesAndIndent();
|
|
22574
|
+
} else {
|
|
22575
|
+
replaceContent = cachedSpaces[1];
|
|
22576
|
+
}
|
|
22577
|
+
break;
|
|
22578
|
+
case 5:
|
|
22579
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
22580
|
+
replaceContent = newLinesAndIndent();
|
|
22581
|
+
} else {
|
|
22582
|
+
replaceContent = cachedSpaces[1];
|
|
22583
|
+
}
|
|
22584
|
+
break;
|
|
22585
|
+
case 12:
|
|
22586
|
+
replaceContent = newLinesAndIndent();
|
|
22587
|
+
break;
|
|
22588
|
+
case 13:
|
|
22589
|
+
if (numberLineBreaks > 0) {
|
|
22590
|
+
replaceContent = newLinesAndIndent();
|
|
22591
|
+
} else if (!needsLineBreak) {
|
|
22592
|
+
replaceContent = cachedSpaces[1];
|
|
22593
|
+
}
|
|
22594
|
+
break;
|
|
22595
|
+
case 6:
|
|
22596
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
22597
|
+
replaceContent = newLinesAndIndent();
|
|
22598
|
+
} else if (!needsLineBreak) {
|
|
22599
|
+
replaceContent = cachedSpaces[1];
|
|
22600
|
+
}
|
|
22601
|
+
break;
|
|
22602
|
+
case 10:
|
|
22603
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
22604
|
+
replaceContent = newLinesAndIndent();
|
|
22605
|
+
} else if (secondToken === 6 && !needsLineBreak) {
|
|
22606
|
+
replaceContent = "";
|
|
22607
|
+
}
|
|
22608
|
+
break;
|
|
22609
|
+
case 7:
|
|
22610
|
+
case 8:
|
|
22611
|
+
case 9:
|
|
22612
|
+
case 11:
|
|
22613
|
+
case 2:
|
|
22614
|
+
case 4:
|
|
22615
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
22616
|
+
replaceContent = newLinesAndIndent();
|
|
22617
|
+
} else {
|
|
22618
|
+
if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) {
|
|
22619
|
+
replaceContent = cachedSpaces[1];
|
|
22620
|
+
} else if (secondToken !== 5 && secondToken !== 17) {
|
|
22621
|
+
hasError = true;
|
|
22622
|
+
}
|
|
22623
|
+
}
|
|
22624
|
+
break;
|
|
22625
|
+
case 16:
|
|
22626
|
+
hasError = true;
|
|
22627
|
+
break;
|
|
22628
|
+
}
|
|
22629
|
+
if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) {
|
|
22630
|
+
replaceContent = newLinesAndIndent();
|
|
22631
|
+
}
|
|
22632
|
+
}
|
|
22633
|
+
if (secondToken === 17) {
|
|
22634
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
22635
|
+
replaceContent = newLinesAndIndent();
|
|
22636
|
+
} else {
|
|
22637
|
+
replaceContent = options.insertFinalNewline ? eol : "";
|
|
22638
|
+
}
|
|
22639
|
+
}
|
|
22640
|
+
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
22641
|
+
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
22642
|
+
firstToken = secondToken;
|
|
22643
|
+
}
|
|
22644
|
+
return editOperations;
|
|
22645
|
+
}
|
|
22646
|
+
function repeat(s, count) {
|
|
22647
|
+
let result = "";
|
|
22648
|
+
for (let i = 0;i < count; i++) {
|
|
22649
|
+
result += s;
|
|
22650
|
+
}
|
|
22651
|
+
return result;
|
|
22652
|
+
}
|
|
22653
|
+
function computeIndentLevel(content, options) {
|
|
22654
|
+
let i = 0;
|
|
22655
|
+
let nChars = 0;
|
|
22656
|
+
const tabSize = options.tabSize || 4;
|
|
22657
|
+
while (i < content.length) {
|
|
22658
|
+
let ch = content.charAt(i);
|
|
22659
|
+
if (ch === cachedSpaces[1]) {
|
|
22660
|
+
nChars++;
|
|
22661
|
+
} else if (ch === "\t") {
|
|
22662
|
+
nChars += tabSize;
|
|
22663
|
+
} else {
|
|
22664
|
+
break;
|
|
22665
|
+
}
|
|
22666
|
+
i++;
|
|
22667
|
+
}
|
|
22668
|
+
return Math.floor(nChars / tabSize);
|
|
22669
|
+
}
|
|
22670
|
+
function getEOL(options, text) {
|
|
22671
|
+
for (let i = 0;i < text.length; i++) {
|
|
22672
|
+
const ch = text.charAt(i);
|
|
22673
|
+
if (ch === "\r") {
|
|
22674
|
+
if (i + 1 < text.length && text.charAt(i + 1) === `
|
|
22675
|
+
`) {
|
|
22676
|
+
return `\r
|
|
22677
|
+
`;
|
|
22678
|
+
}
|
|
22679
|
+
return "\r";
|
|
22680
|
+
} else if (ch === `
|
|
22681
|
+
`) {
|
|
22682
|
+
return `
|
|
22683
|
+
`;
|
|
22684
|
+
}
|
|
22685
|
+
}
|
|
22686
|
+
return options && options.eol || `
|
|
22687
|
+
`;
|
|
22688
|
+
}
|
|
22689
|
+
function isEOL(text, offset) {
|
|
22690
|
+
return `\r
|
|
22691
|
+
`.indexOf(text.charAt(offset)) !== -1;
|
|
22692
|
+
}
|
|
22693
|
+
|
|
22694
|
+
// ../../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
22695
|
+
var ParseOptions;
|
|
22696
|
+
(function(ParseOptions2) {
|
|
22697
|
+
ParseOptions2.DEFAULT = {
|
|
22698
|
+
allowTrailingComma: false
|
|
22699
|
+
};
|
|
22700
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
22701
|
+
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
22702
|
+
let currentProperty = null;
|
|
22703
|
+
let currentParent = [];
|
|
22704
|
+
const previousParents = [];
|
|
22705
|
+
function onValue(value) {
|
|
22706
|
+
if (Array.isArray(currentParent)) {
|
|
22707
|
+
currentParent.push(value);
|
|
22708
|
+
} else if (currentProperty !== null) {
|
|
22709
|
+
currentParent[currentProperty] = value;
|
|
22710
|
+
}
|
|
22711
|
+
}
|
|
22712
|
+
const visitor = {
|
|
22713
|
+
onObjectBegin: () => {
|
|
22714
|
+
const object = {};
|
|
22715
|
+
onValue(object);
|
|
22716
|
+
previousParents.push(currentParent);
|
|
22717
|
+
currentParent = object;
|
|
22718
|
+
currentProperty = null;
|
|
22719
|
+
},
|
|
22720
|
+
onObjectProperty: (name) => {
|
|
22721
|
+
currentProperty = name;
|
|
22722
|
+
},
|
|
22723
|
+
onObjectEnd: () => {
|
|
22724
|
+
currentParent = previousParents.pop();
|
|
22725
|
+
},
|
|
22726
|
+
onArrayBegin: () => {
|
|
22727
|
+
const array = [];
|
|
22728
|
+
onValue(array);
|
|
22729
|
+
previousParents.push(currentParent);
|
|
22730
|
+
currentParent = array;
|
|
22731
|
+
currentProperty = null;
|
|
22732
|
+
},
|
|
22733
|
+
onArrayEnd: () => {
|
|
22734
|
+
currentParent = previousParents.pop();
|
|
22735
|
+
},
|
|
22736
|
+
onLiteralValue: onValue,
|
|
22737
|
+
onError: (error, offset, length) => {
|
|
22738
|
+
errors.push({ error, offset, length });
|
|
22739
|
+
}
|
|
22740
|
+
};
|
|
22741
|
+
visit(text, visitor, options);
|
|
22742
|
+
return currentParent[0];
|
|
22743
|
+
}
|
|
22744
|
+
function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
22745
|
+
let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: undefined };
|
|
22746
|
+
function ensurePropertyComplete(endOffset) {
|
|
22747
|
+
if (currentParent.type === "property") {
|
|
22748
|
+
currentParent.length = endOffset - currentParent.offset;
|
|
22749
|
+
currentParent = currentParent.parent;
|
|
22750
|
+
}
|
|
22751
|
+
}
|
|
22752
|
+
function onValue(valueNode) {
|
|
22753
|
+
currentParent.children.push(valueNode);
|
|
22754
|
+
return valueNode;
|
|
22755
|
+
}
|
|
22756
|
+
const visitor = {
|
|
22757
|
+
onObjectBegin: (offset) => {
|
|
22758
|
+
currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
|
|
22759
|
+
},
|
|
22760
|
+
onObjectProperty: (name, offset, length) => {
|
|
22761
|
+
currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
|
|
22762
|
+
currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
|
|
22763
|
+
},
|
|
22764
|
+
onObjectEnd: (offset, length) => {
|
|
22765
|
+
ensurePropertyComplete(offset + length);
|
|
22766
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
22767
|
+
currentParent = currentParent.parent;
|
|
22768
|
+
ensurePropertyComplete(offset + length);
|
|
22769
|
+
},
|
|
22770
|
+
onArrayBegin: (offset, length) => {
|
|
22771
|
+
currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
|
|
22772
|
+
},
|
|
22773
|
+
onArrayEnd: (offset, length) => {
|
|
22774
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
22775
|
+
currentParent = currentParent.parent;
|
|
22776
|
+
ensurePropertyComplete(offset + length);
|
|
22777
|
+
},
|
|
22778
|
+
onLiteralValue: (value, offset, length) => {
|
|
22779
|
+
onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
|
|
22780
|
+
ensurePropertyComplete(offset + length);
|
|
22781
|
+
},
|
|
22782
|
+
onSeparator: (sep, offset, length) => {
|
|
22783
|
+
if (currentParent.type === "property") {
|
|
22784
|
+
if (sep === ":") {
|
|
22785
|
+
currentParent.colonOffset = offset;
|
|
22786
|
+
} else if (sep === ",") {
|
|
22787
|
+
ensurePropertyComplete(offset);
|
|
22788
|
+
}
|
|
22789
|
+
}
|
|
22790
|
+
},
|
|
22791
|
+
onError: (error, offset, length) => {
|
|
22792
|
+
errors.push({ error, offset, length });
|
|
22793
|
+
}
|
|
22794
|
+
};
|
|
22795
|
+
visit(text, visitor, options);
|
|
22796
|
+
const result = currentParent.children[0];
|
|
22797
|
+
if (result) {
|
|
22798
|
+
delete result.parent;
|
|
22799
|
+
}
|
|
22800
|
+
return result;
|
|
22801
|
+
}
|
|
22802
|
+
function findNodeAtLocation(root, path) {
|
|
22803
|
+
if (!root) {
|
|
22804
|
+
return;
|
|
22805
|
+
}
|
|
22806
|
+
let node = root;
|
|
22807
|
+
for (let segment of path) {
|
|
22808
|
+
if (typeof segment === "string") {
|
|
22809
|
+
if (node.type !== "object" || !Array.isArray(node.children)) {
|
|
22810
|
+
return;
|
|
22811
|
+
}
|
|
22812
|
+
let found = false;
|
|
22813
|
+
for (const propertyNode of node.children) {
|
|
22814
|
+
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
|
|
22815
|
+
node = propertyNode.children[1];
|
|
22816
|
+
found = true;
|
|
22817
|
+
break;
|
|
22818
|
+
}
|
|
22819
|
+
}
|
|
22820
|
+
if (!found) {
|
|
22821
|
+
return;
|
|
22822
|
+
}
|
|
22823
|
+
} else {
|
|
22824
|
+
const index = segment;
|
|
22825
|
+
if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
|
|
22826
|
+
return;
|
|
22827
|
+
}
|
|
22828
|
+
node = node.children[index];
|
|
22829
|
+
}
|
|
22830
|
+
}
|
|
22831
|
+
return node;
|
|
22832
|
+
}
|
|
22833
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
22834
|
+
const _scanner = createScanner(text, false);
|
|
22835
|
+
const _jsonPath = [];
|
|
22836
|
+
let suppressedCallbacks = 0;
|
|
22837
|
+
function toNoArgVisit(visitFunction) {
|
|
22838
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
22839
|
+
}
|
|
22840
|
+
function toOneArgVisit(visitFunction) {
|
|
22841
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
22842
|
+
}
|
|
22843
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
22844
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
22845
|
+
}
|
|
22846
|
+
function toBeginVisit(visitFunction) {
|
|
22847
|
+
return visitFunction ? () => {
|
|
22848
|
+
if (suppressedCallbacks > 0) {
|
|
22849
|
+
suppressedCallbacks++;
|
|
22850
|
+
} else {
|
|
22851
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
22852
|
+
if (cbReturn === false) {
|
|
22853
|
+
suppressedCallbacks = 1;
|
|
22854
|
+
}
|
|
22855
|
+
}
|
|
22856
|
+
} : () => true;
|
|
22857
|
+
}
|
|
22858
|
+
function toEndVisit(visitFunction) {
|
|
22859
|
+
return visitFunction ? () => {
|
|
22860
|
+
if (suppressedCallbacks > 0) {
|
|
22861
|
+
suppressedCallbacks--;
|
|
22862
|
+
}
|
|
22863
|
+
if (suppressedCallbacks === 0) {
|
|
22864
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
22865
|
+
}
|
|
22866
|
+
} : () => true;
|
|
22867
|
+
}
|
|
22868
|
+
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);
|
|
22869
|
+
const disallowComments = options && options.disallowComments;
|
|
22870
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
22871
|
+
function scanNext() {
|
|
22872
|
+
while (true) {
|
|
22873
|
+
const token = _scanner.scan();
|
|
22874
|
+
switch (_scanner.getTokenError()) {
|
|
22875
|
+
case 4:
|
|
22876
|
+
handleError(14);
|
|
22877
|
+
break;
|
|
22878
|
+
case 5:
|
|
22879
|
+
handleError(15);
|
|
22880
|
+
break;
|
|
22881
|
+
case 3:
|
|
22882
|
+
handleError(13);
|
|
22883
|
+
break;
|
|
22884
|
+
case 1:
|
|
22885
|
+
if (!disallowComments) {
|
|
22886
|
+
handleError(11);
|
|
22887
|
+
}
|
|
22888
|
+
break;
|
|
22889
|
+
case 2:
|
|
22890
|
+
handleError(12);
|
|
22891
|
+
break;
|
|
22892
|
+
case 6:
|
|
22893
|
+
handleError(16);
|
|
22894
|
+
break;
|
|
22895
|
+
}
|
|
22896
|
+
switch (token) {
|
|
22897
|
+
case 12:
|
|
22898
|
+
case 13:
|
|
22899
|
+
if (disallowComments) {
|
|
22900
|
+
handleError(10);
|
|
22901
|
+
} else {
|
|
22902
|
+
onComment();
|
|
22903
|
+
}
|
|
22904
|
+
break;
|
|
22905
|
+
case 16:
|
|
22906
|
+
handleError(1);
|
|
22907
|
+
break;
|
|
22908
|
+
case 15:
|
|
22909
|
+
case 14:
|
|
22910
|
+
break;
|
|
22911
|
+
default:
|
|
22912
|
+
return token;
|
|
22913
|
+
}
|
|
22914
|
+
}
|
|
22915
|
+
}
|
|
22916
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
22917
|
+
onError(error);
|
|
22918
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
22919
|
+
let token = _scanner.getToken();
|
|
22920
|
+
while (token !== 17) {
|
|
22921
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
22922
|
+
scanNext();
|
|
22923
|
+
break;
|
|
22924
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
22925
|
+
break;
|
|
22926
|
+
}
|
|
22927
|
+
token = scanNext();
|
|
22928
|
+
}
|
|
22929
|
+
}
|
|
22930
|
+
}
|
|
22931
|
+
function parseString(isValue) {
|
|
22932
|
+
const value = _scanner.getTokenValue();
|
|
22933
|
+
if (isValue) {
|
|
22934
|
+
onLiteralValue(value);
|
|
22935
|
+
} else {
|
|
22936
|
+
onObjectProperty(value);
|
|
22937
|
+
_jsonPath.push(value);
|
|
22938
|
+
}
|
|
22939
|
+
scanNext();
|
|
22940
|
+
return true;
|
|
22941
|
+
}
|
|
22942
|
+
function parseLiteral() {
|
|
22943
|
+
switch (_scanner.getToken()) {
|
|
22944
|
+
case 11:
|
|
22945
|
+
const tokenValue = _scanner.getTokenValue();
|
|
22946
|
+
let value = Number(tokenValue);
|
|
22947
|
+
if (isNaN(value)) {
|
|
22948
|
+
handleError(2);
|
|
22949
|
+
value = 0;
|
|
22950
|
+
}
|
|
22951
|
+
onLiteralValue(value);
|
|
22952
|
+
break;
|
|
22953
|
+
case 7:
|
|
22954
|
+
onLiteralValue(null);
|
|
22955
|
+
break;
|
|
22956
|
+
case 8:
|
|
22957
|
+
onLiteralValue(true);
|
|
22958
|
+
break;
|
|
22959
|
+
case 9:
|
|
22960
|
+
onLiteralValue(false);
|
|
22961
|
+
break;
|
|
22962
|
+
default:
|
|
22963
|
+
return false;
|
|
22964
|
+
}
|
|
22965
|
+
scanNext();
|
|
22966
|
+
return true;
|
|
22967
|
+
}
|
|
22968
|
+
function parseProperty() {
|
|
22969
|
+
if (_scanner.getToken() !== 10) {
|
|
22970
|
+
handleError(3, [], [2, 5]);
|
|
22971
|
+
return false;
|
|
22972
|
+
}
|
|
22973
|
+
parseString(false);
|
|
22974
|
+
if (_scanner.getToken() === 6) {
|
|
22975
|
+
onSeparator(":");
|
|
22976
|
+
scanNext();
|
|
22977
|
+
if (!parseValue()) {
|
|
22978
|
+
handleError(4, [], [2, 5]);
|
|
22979
|
+
}
|
|
22980
|
+
} else {
|
|
22981
|
+
handleError(5, [], [2, 5]);
|
|
22982
|
+
}
|
|
22983
|
+
_jsonPath.pop();
|
|
22984
|
+
return true;
|
|
22985
|
+
}
|
|
22986
|
+
function parseObject() {
|
|
22987
|
+
onObjectBegin();
|
|
22988
|
+
scanNext();
|
|
22989
|
+
let needsComma = false;
|
|
22990
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
22991
|
+
if (_scanner.getToken() === 5) {
|
|
22992
|
+
if (!needsComma) {
|
|
22993
|
+
handleError(4, [], []);
|
|
22994
|
+
}
|
|
22995
|
+
onSeparator(",");
|
|
22996
|
+
scanNext();
|
|
22997
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
22998
|
+
break;
|
|
22999
|
+
}
|
|
23000
|
+
} else if (needsComma) {
|
|
23001
|
+
handleError(6, [], []);
|
|
23002
|
+
}
|
|
23003
|
+
if (!parseProperty()) {
|
|
23004
|
+
handleError(4, [], [2, 5]);
|
|
23005
|
+
}
|
|
23006
|
+
needsComma = true;
|
|
23007
|
+
}
|
|
23008
|
+
onObjectEnd();
|
|
23009
|
+
if (_scanner.getToken() !== 2) {
|
|
23010
|
+
handleError(7, [2], []);
|
|
23011
|
+
} else {
|
|
23012
|
+
scanNext();
|
|
23013
|
+
}
|
|
23014
|
+
return true;
|
|
23015
|
+
}
|
|
23016
|
+
function parseArray() {
|
|
23017
|
+
onArrayBegin();
|
|
23018
|
+
scanNext();
|
|
23019
|
+
let isFirstElement = true;
|
|
23020
|
+
let needsComma = false;
|
|
23021
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
23022
|
+
if (_scanner.getToken() === 5) {
|
|
23023
|
+
if (!needsComma) {
|
|
23024
|
+
handleError(4, [], []);
|
|
23025
|
+
}
|
|
23026
|
+
onSeparator(",");
|
|
23027
|
+
scanNext();
|
|
23028
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
23029
|
+
break;
|
|
23030
|
+
}
|
|
23031
|
+
} else if (needsComma) {
|
|
23032
|
+
handleError(6, [], []);
|
|
23033
|
+
}
|
|
23034
|
+
if (isFirstElement) {
|
|
23035
|
+
_jsonPath.push(0);
|
|
23036
|
+
isFirstElement = false;
|
|
23037
|
+
} else {
|
|
23038
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
23039
|
+
}
|
|
23040
|
+
if (!parseValue()) {
|
|
23041
|
+
handleError(4, [], [4, 5]);
|
|
23042
|
+
}
|
|
23043
|
+
needsComma = true;
|
|
23044
|
+
}
|
|
23045
|
+
onArrayEnd();
|
|
23046
|
+
if (!isFirstElement) {
|
|
23047
|
+
_jsonPath.pop();
|
|
23048
|
+
}
|
|
23049
|
+
if (_scanner.getToken() !== 4) {
|
|
23050
|
+
handleError(8, [4], []);
|
|
23051
|
+
} else {
|
|
23052
|
+
scanNext();
|
|
23053
|
+
}
|
|
23054
|
+
return true;
|
|
23055
|
+
}
|
|
23056
|
+
function parseValue() {
|
|
23057
|
+
switch (_scanner.getToken()) {
|
|
23058
|
+
case 3:
|
|
23059
|
+
return parseArray();
|
|
23060
|
+
case 1:
|
|
23061
|
+
return parseObject();
|
|
23062
|
+
case 10:
|
|
23063
|
+
return parseString(true);
|
|
23064
|
+
default:
|
|
23065
|
+
return parseLiteral();
|
|
23066
|
+
}
|
|
23067
|
+
}
|
|
23068
|
+
scanNext();
|
|
23069
|
+
if (_scanner.getToken() === 17) {
|
|
23070
|
+
if (options.allowEmptyContent) {
|
|
23071
|
+
return true;
|
|
23072
|
+
}
|
|
23073
|
+
handleError(4, [], []);
|
|
23074
|
+
return false;
|
|
23075
|
+
}
|
|
23076
|
+
if (!parseValue()) {
|
|
23077
|
+
handleError(4, [], []);
|
|
23078
|
+
return false;
|
|
23079
|
+
}
|
|
23080
|
+
if (_scanner.getToken() !== 17) {
|
|
23081
|
+
handleError(9, [], []);
|
|
23082
|
+
}
|
|
23083
|
+
return true;
|
|
23084
|
+
}
|
|
23085
|
+
function getNodeType(value) {
|
|
23086
|
+
switch (typeof value) {
|
|
23087
|
+
case "boolean":
|
|
23088
|
+
return "boolean";
|
|
23089
|
+
case "number":
|
|
23090
|
+
return "number";
|
|
23091
|
+
case "string":
|
|
23092
|
+
return "string";
|
|
23093
|
+
case "object": {
|
|
23094
|
+
if (!value) {
|
|
23095
|
+
return "null";
|
|
23096
|
+
} else if (Array.isArray(value)) {
|
|
23097
|
+
return "array";
|
|
23098
|
+
}
|
|
23099
|
+
return "object";
|
|
23100
|
+
}
|
|
23101
|
+
default:
|
|
23102
|
+
return "null";
|
|
23103
|
+
}
|
|
23104
|
+
}
|
|
23105
|
+
|
|
23106
|
+
// ../../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/edit.js
|
|
23107
|
+
function setProperty(text, originalPath, value, options) {
|
|
23108
|
+
const path = originalPath.slice();
|
|
23109
|
+
const errors = [];
|
|
23110
|
+
const root = parseTree(text, errors);
|
|
23111
|
+
let parent = undefined;
|
|
23112
|
+
let lastSegment = undefined;
|
|
23113
|
+
while (path.length > 0) {
|
|
23114
|
+
lastSegment = path.pop();
|
|
23115
|
+
parent = findNodeAtLocation(root, path);
|
|
23116
|
+
if (parent === undefined && value !== undefined) {
|
|
23117
|
+
if (typeof lastSegment === "string") {
|
|
23118
|
+
value = { [lastSegment]: value };
|
|
23119
|
+
} else {
|
|
23120
|
+
value = [value];
|
|
23121
|
+
}
|
|
23122
|
+
} else {
|
|
23123
|
+
break;
|
|
23124
|
+
}
|
|
23125
|
+
}
|
|
23126
|
+
if (!parent) {
|
|
23127
|
+
if (value === undefined) {
|
|
23128
|
+
throw new Error("Can not delete in empty document");
|
|
23129
|
+
}
|
|
23130
|
+
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
|
|
23131
|
+
} else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
|
|
23132
|
+
const existing = findNodeAtLocation(parent, [lastSegment]);
|
|
23133
|
+
if (existing !== undefined) {
|
|
23134
|
+
if (value === undefined) {
|
|
23135
|
+
if (!existing.parent) {
|
|
23136
|
+
throw new Error("Malformed AST");
|
|
23137
|
+
}
|
|
23138
|
+
const propertyIndex = parent.children.indexOf(existing.parent);
|
|
23139
|
+
let removeBegin;
|
|
23140
|
+
let removeEnd = existing.parent.offset + existing.parent.length;
|
|
23141
|
+
if (propertyIndex > 0) {
|
|
23142
|
+
let previous = parent.children[propertyIndex - 1];
|
|
23143
|
+
removeBegin = previous.offset + previous.length;
|
|
23144
|
+
} else {
|
|
23145
|
+
removeBegin = parent.offset + 1;
|
|
23146
|
+
if (parent.children.length > 1) {
|
|
23147
|
+
let next = parent.children[1];
|
|
23148
|
+
removeEnd = next.offset;
|
|
23149
|
+
}
|
|
23150
|
+
}
|
|
23151
|
+
return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: "" }, options);
|
|
23152
|
+
} else {
|
|
23153
|
+
return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
|
|
23154
|
+
}
|
|
23155
|
+
} else {
|
|
23156
|
+
if (value === undefined) {
|
|
23157
|
+
return [];
|
|
23158
|
+
}
|
|
23159
|
+
const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
|
|
23160
|
+
const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
|
|
23161
|
+
let edit;
|
|
23162
|
+
if (index > 0) {
|
|
23163
|
+
let previous = parent.children[index - 1];
|
|
23164
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
23165
|
+
} else if (parent.children.length === 0) {
|
|
23166
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
23167
|
+
} else {
|
|
23168
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty + "," };
|
|
23169
|
+
}
|
|
23170
|
+
return withFormatting(text, edit, options);
|
|
23171
|
+
}
|
|
23172
|
+
} else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
|
|
23173
|
+
const insertIndex = lastSegment;
|
|
23174
|
+
if (insertIndex === -1) {
|
|
23175
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
23176
|
+
let edit;
|
|
23177
|
+
if (parent.children.length === 0) {
|
|
23178
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
23179
|
+
} else {
|
|
23180
|
+
const previous = parent.children[parent.children.length - 1];
|
|
23181
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
23182
|
+
}
|
|
23183
|
+
return withFormatting(text, edit, options);
|
|
23184
|
+
} else if (value === undefined && parent.children.length >= 0) {
|
|
23185
|
+
const removalIndex = lastSegment;
|
|
23186
|
+
const toRemove = parent.children[removalIndex];
|
|
23187
|
+
let edit;
|
|
23188
|
+
if (parent.children.length === 1) {
|
|
23189
|
+
edit = { offset: parent.offset + 1, length: parent.length - 2, content: "" };
|
|
23190
|
+
} else if (parent.children.length - 1 === removalIndex) {
|
|
23191
|
+
let previous = parent.children[removalIndex - 1];
|
|
23192
|
+
let offset = previous.offset + previous.length;
|
|
23193
|
+
let parentEndOffset = parent.offset + parent.length;
|
|
23194
|
+
edit = { offset, length: parentEndOffset - 2 - offset, content: "" };
|
|
23195
|
+
} else {
|
|
23196
|
+
edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: "" };
|
|
23197
|
+
}
|
|
23198
|
+
return withFormatting(text, edit, options);
|
|
23199
|
+
} else if (value !== undefined) {
|
|
23200
|
+
let edit;
|
|
23201
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
23202
|
+
if (!options.isArrayInsertion && parent.children.length > lastSegment) {
|
|
23203
|
+
const toModify = parent.children[lastSegment];
|
|
23204
|
+
edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
|
|
23205
|
+
} else if (parent.children.length === 0 || lastSegment === 0) {
|
|
23206
|
+
edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + "," };
|
|
23207
|
+
} else {
|
|
23208
|
+
const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
|
|
23209
|
+
const previous = parent.children[index - 1];
|
|
23210
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
23211
|
+
}
|
|
23212
|
+
return withFormatting(text, edit, options);
|
|
23213
|
+
} else {
|
|
23214
|
+
throw new Error(`Can not ${value === undefined ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
|
|
23215
|
+
}
|
|
23216
|
+
} else {
|
|
23217
|
+
throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
|
|
23218
|
+
}
|
|
23219
|
+
}
|
|
23220
|
+
function withFormatting(text, edit, options) {
|
|
23221
|
+
if (!options.formattingOptions) {
|
|
23222
|
+
return [edit];
|
|
23223
|
+
}
|
|
23224
|
+
let newText = applyEdit(text, edit);
|
|
23225
|
+
let begin = edit.offset;
|
|
23226
|
+
let end = edit.offset + edit.content.length;
|
|
23227
|
+
if (edit.length === 0 || edit.content.length === 0) {
|
|
23228
|
+
while (begin > 0 && !isEOL(newText, begin - 1)) {
|
|
23229
|
+
begin--;
|
|
23230
|
+
}
|
|
23231
|
+
while (end < newText.length && !isEOL(newText, end)) {
|
|
23232
|
+
end++;
|
|
23233
|
+
}
|
|
23234
|
+
}
|
|
23235
|
+
const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
|
|
23236
|
+
for (let i = edits.length - 1;i >= 0; i--) {
|
|
23237
|
+
const edit2 = edits[i];
|
|
23238
|
+
newText = applyEdit(newText, edit2);
|
|
23239
|
+
begin = Math.min(begin, edit2.offset);
|
|
23240
|
+
end = Math.max(end, edit2.offset + edit2.length);
|
|
23241
|
+
end += edit2.content.length - edit2.length;
|
|
23242
|
+
}
|
|
23243
|
+
const editLength = text.length - (newText.length - end) - begin;
|
|
23244
|
+
return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
|
|
23245
|
+
}
|
|
23246
|
+
function applyEdit(text, edit) {
|
|
23247
|
+
return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
|
|
23248
|
+
}
|
|
23249
|
+
|
|
23250
|
+
// ../../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/main.js
|
|
23251
|
+
var ScanError;
|
|
23252
|
+
(function(ScanError2) {
|
|
23253
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
23254
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
23255
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
23256
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
23257
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
23258
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
23259
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
23260
|
+
})(ScanError || (ScanError = {}));
|
|
23261
|
+
var SyntaxKind;
|
|
23262
|
+
(function(SyntaxKind2) {
|
|
23263
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
23264
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
23265
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
23266
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
23267
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
23268
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
23269
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
23270
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
23271
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
23272
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
23273
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
23274
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
23275
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
23276
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
23277
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
23278
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
23279
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
23280
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
23281
|
+
var parse2 = parse;
|
|
23282
|
+
var ParseErrorCode;
|
|
23283
|
+
(function(ParseErrorCode2) {
|
|
23284
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
23285
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
23286
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
23287
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
23288
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
23289
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
23290
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
23291
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
23292
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
23293
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
23294
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
23295
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
23296
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
23297
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
23298
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
23299
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
23300
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
23301
|
+
function modify(text, path, value, options) {
|
|
23302
|
+
return setProperty(text, path, value, options);
|
|
23303
|
+
}
|
|
23304
|
+
function applyEdits(text, edits) {
|
|
23305
|
+
let sortedEdits = edits.slice(0).sort((a, b) => {
|
|
23306
|
+
const diff = a.offset - b.offset;
|
|
23307
|
+
if (diff === 0) {
|
|
23308
|
+
return a.length - b.length;
|
|
23309
|
+
}
|
|
23310
|
+
return diff;
|
|
23311
|
+
});
|
|
23312
|
+
let lastModifiedOffset = text.length;
|
|
23313
|
+
for (let i = sortedEdits.length - 1;i >= 0; i--) {
|
|
23314
|
+
let e = sortedEdits[i];
|
|
23315
|
+
if (e.offset + e.length <= lastModifiedOffset) {
|
|
23316
|
+
text = applyEdit(text, e);
|
|
23317
|
+
} else {
|
|
23318
|
+
throw new Error("Overlapping edit");
|
|
23319
|
+
}
|
|
23320
|
+
lastModifiedOffset = e.offset;
|
|
23321
|
+
}
|
|
23322
|
+
return text;
|
|
23323
|
+
}
|
|
23324
|
+
|
|
21923
23325
|
// src/plugin-bundle.ts
|
|
21924
23326
|
var PLUGIN_BUNDLE = `var AJ=Object.defineProperty;var SJ=($)=>$;function FJ($,z){this[$]=SJ.bind(null,z)}var y$=($,z)=>{for(var I in z)AJ($,I,{get:z[I],enumerable:!0,configurable:!0,set:FJ.bind(z,I)})};import{homedir as qJ}from"node:os";import{join as DJ}from"node:path";import{createRequire as RJ}from"node:module";import{dirname as z2,join as hV}from"node:path";import{fileURLToPath as I2}from"node:url";import{createRequire as J9}from"node:module";import{homedir as bU,platform as q9}from"node:os";import{basename as aV,dirname as tV,resolve as Y6}from"node:path";import{existsSync as X4,readFileSync as nU,readdirSync as UQ,realpathSync as zQ,statSync as IQ}from"node:fs";import{dirname as OQ,join as iU}from"node:path";import{homedir as w9}from"node:os";var{create:MJ,getPrototypeOf:TJ,defineProperty:uO,getOwnPropertyNames:EJ}=Object,vJ=Object.prototype.hasOwnProperty;function CJ($){return this[$]}var PJ,wJ,sO=($,z,I)=>{var O=$!=null&&typeof $==="object";if(O){var U=z?PJ??=new WeakMap:wJ??=new WeakMap,_=U.get($);if(_)return _}I=$!=null?MJ(TJ($)):{};let j=z||!$||!$.__esModule?uO(I,"default",{value:$,enumerable:!0}):I;for(let V of EJ($))if(!vJ.call(j,V))uO(j,V,{get:CJ.bind($,V),enumerable:!0});if(O)U.set($,j);return j},w=($,z)=>()=>(z||$((z={exports:{}}).exports,z),z.exports),G4=RJ(import.meta.url),u=w(($)=>{var z=Symbol.for("yaml.alias"),I=Symbol.for("yaml.document"),O=Symbol.for("yaml.map"),U=Symbol.for("yaml.pair"),_=Symbol.for("yaml.scalar"),j=Symbol.for("yaml.seq"),V=Symbol.for("yaml.node.type"),Y=(B)=>!!B&&typeof B==="object"&&B[V]===z,G=(B)=>!!B&&typeof B==="object"&&B[V]===I,H=(B)=>!!B&&typeof B==="object"&&B[V]===O,J=(B)=>!!B&&typeof B==="object"&&B[V]===U,X=(B)=>!!B&&typeof B==="object"&&B[V]===_,W=(B)=>!!B&&typeof B==="object"&&B[V]===j;function Q(B){if(B&&typeof B==="object")switch(B[V]){case O:case j:return!0}return!1}function N(B){if(B&&typeof B==="object")switch(B[V]){case z:case O:case _:case j:return!0}return!1}var K=(B)=>(X(B)||Q(B))&&!!B.anchor;$.ALIAS=z,$.DOC=I,$.MAP=O,$.NODE_TYPE=V,$.PAIR=U,$.SCALAR=_,$.SEQ=j,$.hasAnchor=K,$.isAlias=Y,$.isCollection=Q,$.isDocument=G,$.isMap=H,$.isNode=N,$.isPair=J,$.isScalar=X,$.isSeq=W}),W4=w(($)=>{var z=u(),I=Symbol("break visit"),O=Symbol("skip children"),U=Symbol("remove node");function _(X,W){let Q=G(W);if(z.isDocument(X)){if(j(null,X.contents,Q,Object.freeze([X]))===U)X.contents=null}else j(null,X,Q,Object.freeze([]))}_.BREAK=I,_.SKIP=O,_.REMOVE=U;function j(X,W,Q,N){let K=H(X,W,Q,N);if(z.isNode(K)||z.isPair(K))return J(X,N,K),j(X,K,Q,N);if(typeof K!=="symbol"){if(z.isCollection(W)){N=Object.freeze(N.concat(W));for(let B=0;B<W.items.length;++B){let L=j(B,W.items[B],Q,N);if(typeof L==="number")B=L-1;else if(L===I)return I;else if(L===U)W.items.splice(B,1),B-=1}}else if(z.isPair(W)){N=Object.freeze(N.concat(W));let B=j("key",W.key,Q,N);if(B===I)return I;else if(B===U)W.key=null;let L=j("value",W.value,Q,N);if(L===I)return I;else if(L===U)W.value=null}}return K}async function V(X,W){let Q=G(W);if(z.isDocument(X)){if(await Y(null,X.contents,Q,Object.freeze([X]))===U)X.contents=null}else await Y(null,X,Q,Object.freeze([]))}V.BREAK=I,V.SKIP=O,V.REMOVE=U;async function Y(X,W,Q,N){let K=await H(X,W,Q,N);if(z.isNode(K)||z.isPair(K))return J(X,N,K),Y(X,K,Q,N);if(typeof K!=="symbol"){if(z.isCollection(W)){N=Object.freeze(N.concat(W));for(let B=0;B<W.items.length;++B){let L=await Y(B,W.items[B],Q,N);if(typeof L==="number")B=L-1;else if(L===I)return I;else if(L===U)W.items.splice(B,1),B-=1}}else if(z.isPair(W)){N=Object.freeze(N.concat(W));let B=await Y("key",W.key,Q,N);if(B===I)return I;else if(B===U)W.key=null;let L=await Y("value",W.value,Q,N);if(L===I)return I;else if(L===U)W.value=null}}return K}function G(X){if(typeof X==="object"&&(X.Collection||X.Node||X.Value))return Object.assign({Alias:X.Node,Map:X.Node,Scalar:X.Node,Seq:X.Node},X.Value&&{Map:X.Value,Scalar:X.Value,Seq:X.Value},X.Collection&&{Map:X.Collection,Seq:X.Collection},X);return X}function H(X,W,Q,N){if(typeof Q==="function")return Q(X,W,N);if(z.isMap(W))return Q.Map?.(X,W,N);if(z.isSeq(W))return Q.Seq?.(X,W,N);if(z.isPair(W))return Q.Pair?.(X,W,N);if(z.isScalar(W))return Q.Scalar?.(X,W,N);if(z.isAlias(W))return Q.Alias?.(X,W,N);return}function J(X,W,Q){let N=W[W.length-1];if(z.isCollection(N))N.items[X]=Q;else if(z.isPair(N))if(X==="key")N.key=Q;else N.value=Q;else if(z.isDocument(N))N.contents=Q;else{let K=z.isAlias(N)?"alias":"scalar";throw Error(\`Cannot replace node with \${K} parent\`)}}$.visit=_,$.visitAsync=V}),eO=w(($)=>{var z=u(),I=W4(),O={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},U=(j)=>j.replace(/[!,[\\]{}]/g,(V)=>O[V]);class _{constructor(j,V){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},_.defaultYaml,j),this.tags=Object.assign({},_.defaultTags,V)}clone(){let j=new _(this.yaml,this.tags);return j.docStart=this.docStart,j}atDocument(){let j=new _(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:_.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},_.defaultTags);break}return j}add(j,V){if(this.atNextDocument)this.yaml={explicit:_.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},_.defaultTags),this.atNextDocument=!1;let Y=j.trim().split(/[ \\t]+/),G=Y.shift();switch(G){case"%TAG":{if(Y.length!==2){if(V(0,"%TAG directive should contain exactly two parts"),Y.length<2)return!1}let[H,J]=Y;return this.tags[H]=J,!0}case"%YAML":{if(this.yaml.explicit=!0,Y.length!==1)return V(0,"%YAML directive should contain exactly one part"),!1;let[H]=Y;if(H==="1.1"||H==="1.2")return this.yaml.version=H,!0;else{let J=/^\\d+\\.\\d+$/.test(H);return V(6,\`Unsupported YAML version \${H}\`,J),!1}}default:return V(0,\`Unknown directive \${G}\`,!0),!1}}tagName(j,V){if(j==="!")return"!";if(j[0]!=="!")return V(\`Not a valid tag: \${j}\`),null;if(j[1]==="<"){let J=j.slice(2,-1);if(J==="!"||J==="!!")return V(\`Verbatim tags aren't resolved, so \${j} is invalid.\`),null;if(j[j.length-1]!==">")V("Verbatim tags must end with a >");return J}let[,Y,G]=j.match(/^(.*!)([^!]*)$/s);if(!G)V(\`The \${j} tag has no suffix\`);let H=this.tags[Y];if(H)try{return H+decodeURIComponent(G)}catch(J){return V(String(J)),null}if(Y==="!")return j;return V(\`Could not resolve tag: \${j}\`),null}tagString(j){for(let[V,Y]of Object.entries(this.tags))if(j.startsWith(Y))return V+U(j.substring(Y.length));return j[0]==="!"?j:\`!<\${j}>\`}toString(j){let V=this.yaml.explicit?[\`%YAML \${this.yaml.version||"1.2"}\`]:[],Y=Object.entries(this.tags),G;if(j&&Y.length>0&&z.isNode(j.contents)){let H={};I.visit(j.contents,(J,X)=>{if(z.isNode(X)&&X.tag)H[X.tag]=!0}),G=Object.keys(H)}else G=[];for(let[H,J]of Y){if(H==="!!"&&J==="tag:yaml.org,2002:")continue;if(!j||G.some((X)=>X.startsWith(J)))V.push(\`%TAG \${H} \${J}\`)}return V.join(\`
|
|
21925
23327
|
\`)}}_.defaultYaml={explicit:!1,version:"1.2"},_.defaultTags={"!!":"tag:yaml.org,2002:"},$.Directives=_}),yU=w(($)=>{var z=u(),I=W4();function O(V){if(/[\\x00-\\x19\\s,[\\]{}]/.test(V)){let G=\`Anchor must not contain whitespace or control characters: \${JSON.stringify(V)}\`;throw Error(G)}return!0}function U(V){let Y=new Set;return I.visit(V,{Value(G,H){if(H.anchor)Y.add(H.anchor)}}),Y}function _(V,Y){for(let G=1;;++G){let H=\`\${V}\${G}\`;if(!Y.has(H))return H}}function j(V,Y){let G=[],H=new Map,J=null;return{onAnchor:(X)=>{G.push(X),J??(J=U(V));let W=_(Y,J);return J.add(W),W},setAnchors:()=>{for(let X of G){let W=H.get(X);if(typeof W==="object"&&W.anchor&&(z.isScalar(W.node)||z.isCollection(W.node)))W.node.anchor=W.anchor;else{let Q=Error("Failed to resolve repeated object (this should not happen)");throw Q.source=X,Q}}},sourceObjects:H}}$.anchorIsValid=O,$.anchorNames=U,$.createNodeAnchors=j,$.findNewAnchor=_}),$0=w(($)=>{function z(I,O,U,_){if(_&&typeof _==="object")if(Array.isArray(_))for(let j=0,V=_.length;j<V;++j){let Y=_[j],G=z(I,_,String(j),Y);if(G===void 0)delete _[j];else if(G!==Y)_[j]=G}else if(_ instanceof Map)for(let j of Array.from(_.keys())){let V=_.get(j),Y=z(I,_,j,V);if(Y===void 0)_.delete(j);else if(Y!==V)_.set(j,Y)}else if(_ instanceof Set)for(let j of Array.from(_)){let V=z(I,_,j,j);if(V===void 0)_.delete(j);else if(V!==j)_.delete(j),_.add(V)}else for(let[j,V]of Object.entries(_)){let Y=z(I,_,j,V);if(Y===void 0)delete _[j];else if(Y!==V)_[j]=Y}return I.call(O,U,_)}$.applyReviver=z}),m$=w(($)=>{var z=u();function I(O,U,_){if(Array.isArray(O))return O.map((j,V)=>I(j,String(V),_));if(O&&typeof O.toJSON==="function"){if(!_||!z.hasAnchor(O))return O.toJSON(U,_);let j={aliasCount:0,count:1,res:void 0};_.anchors.set(O,j),_.onCreate=(Y)=>{j.res=Y,delete _.onCreate};let V=O.toJSON(U,_);if(_.onCreate)_.onCreate(V);return V}if(typeof O==="bigint"&&!_?.keep)return Number(O);return O}$.toJS=I}),hU=w(($)=>{var z=$0(),I=u(),O=m$();class U{constructor(_){Object.defineProperty(this,I.NODE_TYPE,{value:_})}clone(){let _=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));if(this.range)_.range=this.range.slice();return _}toJS(_,{mapAsMap:j,maxAliasCount:V,onAnchor:Y,reviver:G}={}){if(!I.isDocument(_))throw TypeError("A document argument is required");let H={anchors:new Map,doc:_,keep:!0,mapAsMap:j===!0,mapKeyWarned:!1,maxAliasCount:typeof V==="number"?V:100},J=O.toJS(this,"",H);if(typeof Y==="function")for(let{count:X,res:W}of H.anchors.values())Y(W,X);return typeof G==="function"?z.applyReviver(G,{"":J},"",J):J}}$.NodeBase=U}),V4=w(($)=>{var z=yU(),I=W4(),O=u(),U=hU(),_=m$();class j extends U.NodeBase{constructor(Y){super(O.ALIAS);this.source=Y,Object.defineProperty(this,"tag",{set(){throw Error("Alias nodes cannot have tags")}})}resolve(Y,G){let H;if(G?.aliasResolveCache)H=G.aliasResolveCache;else if(H=[],I.visit(Y,{Node:(X,W)=>{if(O.isAlias(W)||O.hasAnchor(W))H.push(W)}}),G)G.aliasResolveCache=H;let J=void 0;for(let X of H){if(X===this)break;if(X.anchor===this.source)J=X}return J}toJSON(Y,G){if(!G)return{source:this.source};let{anchors:H,doc:J,maxAliasCount:X}=G,W=this.resolve(J,G);if(!W){let N=\`Unresolved alias (the anchor must be set before the alias): \${this.source}\`;throw ReferenceError(N)}let Q=H.get(W);if(!Q)_.toJS(W,null,G),Q=H.get(W);if(Q?.res===void 0)throw ReferenceError("This should not happen: Alias anchor was not resolved?");if(X>=0){if(Q.count+=1,Q.aliasCount===0)Q.aliasCount=V(J,W,H);if(Q.count*Q.aliasCount>X)throw ReferenceError("Excessive alias count indicates a resource exhaustion attack")}return Q.res}toString(Y,G,H){let J=\`*\${this.source}\`;if(Y){if(z.anchorIsValid(this.source),Y.options.verifyAliasOrder&&!Y.anchors.has(this.source)){let X=\`Unresolved alias (the anchor must be set before the alias): \${this.source}\`;throw Error(X)}if(Y.implicitKey)return\`\${J} \`}return J}}function V(Y,G,H){if(O.isAlias(G)){let J=G.resolve(Y),X=H&&J&&H.get(J);return X?X.count*X.aliasCount:0}else if(O.isCollection(G)){let J=0;for(let X of G.items){let W=V(Y,X,H);if(W>J)J=W}return J}else if(O.isPair(G)){let J=V(Y,G.key,H),X=V(Y,G.value,H);return Math.max(J,X)}return 1}$.Alias=j}),a=w(($)=>{var z=u(),I=hU(),O=m$(),U=(j)=>!j||typeof j!=="function"&&typeof j!=="object";class _ extends I.NodeBase{constructor(j){super(z.SCALAR);this.value=j}toJSON(j,V){return V?.keep?this.value:O.toJS(this.value,j,V)}toString(){return String(this.value)}}_.BLOCK_FOLDED="BLOCK_FOLDED",_.BLOCK_LITERAL="BLOCK_LITERAL",_.PLAIN="PLAIN",_.QUOTE_DOUBLE="QUOTE_DOUBLE",_.QUOTE_SINGLE="QUOTE_SINGLE",$.Scalar=_,$.isScalarValue=U}),Q4=w(($)=>{var z=V4(),I=u(),O=a(),U="tag:yaml.org,2002:";function _(V,Y,G){if(Y){let H=G.filter((X)=>X.tag===Y),J=H.find((X)=>!X.format)??H[0];if(!J)throw Error(\`Tag \${Y} not found\`);return J}return G.find((H)=>H.identify?.(V)&&!H.format)}function j(V,Y,G){if(I.isDocument(V))V=V.contents;if(I.isNode(V))return V;if(I.isPair(V)){let L=G.schema[I.MAP].createNode?.(G.schema,null,G);return L.items.push(V),L}if(V instanceof String||V instanceof Number||V instanceof Boolean||typeof BigInt<"u"&&V instanceof BigInt)V=V.valueOf();let{aliasDuplicateObjects:H,onAnchor:J,onTagObj:X,schema:W,sourceObjects:Q}=G,N=void 0;if(H&&V&&typeof V==="object")if(N=Q.get(V),N)return N.anchor??(N.anchor=J(V)),new z.Alias(N.anchor);else N={anchor:null,node:null},Q.set(V,N);if(Y?.startsWith("!!"))Y=U+Y.slice(2);let K=_(V,Y,W.tags);if(!K){if(V&&typeof V.toJSON==="function")V=V.toJSON();if(!V||typeof V!=="object"){let L=new O.Scalar(V);if(N)N.node=L;return L}K=V instanceof Map?W[I.MAP]:(Symbol.iterator in Object(V))?W[I.SEQ]:W[I.MAP]}if(X)X(K),delete G.onTagObj;let B=K?.createNode?K.createNode(G.schema,V,G):typeof K?.nodeClass?.from==="function"?K.nodeClass.from(G.schema,V,G):new O.Scalar(V);if(Y)B.tag=Y;else if(!K.default)B.tag=K.tag;if(N)N.node=B;return B}$.createNode=j}),uU=w(($)=>{var z=Q4(),I=u(),O=hU();function U(V,Y,G){let H=G;for(let J=Y.length-1;J>=0;--J){let X=Y[J];if(typeof X==="number"&&Number.isInteger(X)&&X>=0){let W=[];W[X]=H,H=W}else H=new Map([[X,H]])}return z.createNode(H,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw Error("This should not happen, please report a bug.")},schema:V,sourceObjects:new Map})}var _=(V)=>V==null||typeof V==="object"&&!!V[Symbol.iterator]().next().done;class j extends O.NodeBase{constructor(V,Y){super(V);Object.defineProperty(this,"schema",{value:Y,configurable:!0,enumerable:!1,writable:!0})}clone(V){let Y=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));if(V)Y.schema=V;if(Y.items=Y.items.map((G)=>I.isNode(G)||I.isPair(G)?G.clone(V):G),this.range)Y.range=this.range.slice();return Y}addIn(V,Y){if(_(V))this.add(Y);else{let[G,...H]=V,J=this.get(G,!0);if(I.isCollection(J))J.addIn(H,Y);else if(J===void 0&&this.schema)this.set(G,U(this.schema,H,Y));else throw Error(\`Expected YAML collection at \${G}. Remaining path: \${H}\`)}}deleteIn(V){let[Y,...G]=V;if(G.length===0)return this.delete(Y);let H=this.get(Y,!0);if(I.isCollection(H))return H.deleteIn(G);else throw Error(\`Expected YAML collection at \${Y}. Remaining path: \${G}\`)}getIn(V,Y){let[G,...H]=V,J=this.get(G,!0);if(H.length===0)return!Y&&I.isScalar(J)?J.value:J;else return I.isCollection(J)?J.getIn(H,Y):void 0}hasAllNullValues(V){return this.items.every((Y)=>{if(!I.isPair(Y))return!1;let G=Y.value;return G==null||V&&I.isScalar(G)&&G.value==null&&!G.commentBefore&&!G.comment&&!G.tag})}hasIn(V){let[Y,...G]=V;if(G.length===0)return this.has(Y);let H=this.get(Y,!0);return I.isCollection(H)?H.hasIn(G):!1}setIn(V,Y){let[G,...H]=V;if(H.length===0)this.set(G,Y);else{let J=this.get(G,!0);if(I.isCollection(J))J.setIn(H,Y);else if(J===void 0&&this.schema)this.set(G,U(this.schema,H,Y));else throw Error(\`Expected YAML collection at \${G}. Remaining path: \${H}\`)}}}$.Collection=j,$.collectionFromPath=U,$.isEmptyPath=_}),H4=w(($)=>{var z=(U)=>U.replace(/^(?!$)(?: $)?/gm,"#");function I(U,_){if(/^\\n+$/.test(U))return U.substring(1);return _?U.replace(/^(?! *$)/gm,_):U}var O=(U,_,j)=>U.endsWith(\`
|
|
@@ -24162,6 +25564,7 @@ Set the \\\`cycles\\\` parameter to \\\`"ref"\\\` to resolve cyclical schemas wi
|
|
|
24162
25564
|
`;
|
|
24163
25565
|
|
|
24164
25566
|
// src/index.ts
|
|
25567
|
+
var API_KEY_FILE_NAME = ".signet-api-key";
|
|
24165
25568
|
function isJsonObject(value) {
|
|
24166
25569
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24167
25570
|
}
|
|
@@ -24171,7 +25574,7 @@ function readTrimmedEnv(name) {
|
|
|
24171
25574
|
}
|
|
24172
25575
|
function signetRuntimeEnv() {
|
|
24173
25576
|
const env = {};
|
|
24174
|
-
const daemonUrl =
|
|
25577
|
+
const daemonUrl = configuredDaemonUrl();
|
|
24175
25578
|
const apiKey = readTrimmedEnv("SIGNET_API_KEY") ?? readTrimmedEnv("SIGNET_TOKEN");
|
|
24176
25579
|
const agentId = readTrimmedEnv("SIGNET_AGENT_ID");
|
|
24177
25580
|
if (daemonUrl)
|
|
@@ -24182,135 +25585,61 @@ function signetRuntimeEnv() {
|
|
|
24182
25585
|
env.SIGNET_AGENT_ID = agentId;
|
|
24183
25586
|
return env;
|
|
24184
25587
|
}
|
|
24185
|
-
function buildPluginBundle() {
|
|
25588
|
+
function buildPluginBundle(apiKeyFilePath) {
|
|
24186
25589
|
const env = signetRuntimeEnv();
|
|
24187
|
-
|
|
24188
|
-
|
|
25590
|
+
if (apiKeyFilePath)
|
|
25591
|
+
delete env.SIGNET_API_KEY;
|
|
25592
|
+
const assignments = Object.entries(env).map(([key, value]) => `process.env[${JSON.stringify(key)}] = ${JSON.stringify(value)};`);
|
|
25593
|
+
if (apiKeyFilePath) {
|
|
25594
|
+
assignments.unshift('import { readFileSync as __signetReadFileSync } from "node:fs";');
|
|
25595
|
+
assignments.push(`process.env["SIGNET_API_KEY"] = __signetReadFileSync(${JSON.stringify(apiKeyFilePath)}, "utf-8").trim();`);
|
|
25596
|
+
}
|
|
25597
|
+
if (assignments.length === 0)
|
|
24189
25598
|
return PLUGIN_BUNDLE;
|
|
24190
|
-
|
|
24191
|
-
`)
|
|
24192
|
-
return `${bootstrap}
|
|
25599
|
+
return `${assignments.join(`
|
|
25600
|
+
`)}
|
|
24193
25601
|
${PLUGIN_BUNDLE}`;
|
|
24194
25602
|
}
|
|
24195
|
-
function
|
|
24196
|
-
|
|
24197
|
-
|
|
24198
|
-
|
|
24199
|
-
|
|
24200
|
-
|
|
24201
|
-
|
|
24202
|
-
|
|
25603
|
+
function parseJsonOrJsonc(raw) {
|
|
25604
|
+
const errors = [];
|
|
25605
|
+
const parsed = parse2(raw.replace(/^\uFEFF/, ""), errors, {
|
|
25606
|
+
allowTrailingComma: true,
|
|
25607
|
+
disallowComments: false
|
|
25608
|
+
});
|
|
25609
|
+
if (errors.length > 0) {
|
|
25610
|
+
const first = errors[0];
|
|
25611
|
+
throw new Error(`Invalid OpenCode JSONC at offset ${first.offset} (code ${first.error})`);
|
|
24203
25612
|
}
|
|
24204
|
-
|
|
25613
|
+
if (!isJsonObject(parsed))
|
|
25614
|
+
throw new Error("OpenCode config must be a top-level object");
|
|
25615
|
+
return parsed;
|
|
24205
25616
|
}
|
|
24206
|
-
function
|
|
24207
|
-
|
|
24208
|
-
|
|
24209
|
-
|
|
24210
|
-
|
|
24211
|
-
|
|
24212
|
-
|
|
24213
|
-
|
|
24214
|
-
|
|
24215
|
-
|
|
24216
|
-
if (inSingleLineComment) {
|
|
24217
|
-
if (ch === `
|
|
24218
|
-
`) {
|
|
24219
|
-
inSingleLineComment = false;
|
|
24220
|
-
result += ch;
|
|
24221
|
-
}
|
|
24222
|
-
continue;
|
|
24223
|
-
}
|
|
24224
|
-
if (inMultiLineComment) {
|
|
24225
|
-
if (ch === "*" && next === "/") {
|
|
24226
|
-
inMultiLineComment = false;
|
|
24227
|
-
i++;
|
|
24228
|
-
}
|
|
24229
|
-
continue;
|
|
24230
|
-
}
|
|
24231
|
-
if (inString) {
|
|
24232
|
-
result += ch;
|
|
24233
|
-
if (escaped) {
|
|
24234
|
-
escaped = false;
|
|
24235
|
-
} else if (ch === "\\") {
|
|
24236
|
-
escaped = true;
|
|
24237
|
-
} else if (ch === quote) {
|
|
24238
|
-
inString = false;
|
|
24239
|
-
}
|
|
24240
|
-
continue;
|
|
24241
|
-
}
|
|
24242
|
-
if (ch === '"' || ch === "'") {
|
|
24243
|
-
inString = true;
|
|
24244
|
-
quote = ch;
|
|
24245
|
-
result += ch;
|
|
24246
|
-
continue;
|
|
24247
|
-
}
|
|
24248
|
-
if (ch === "/" && next === "/") {
|
|
24249
|
-
inSingleLineComment = true;
|
|
24250
|
-
i++;
|
|
24251
|
-
continue;
|
|
24252
|
-
}
|
|
24253
|
-
if (ch === "/" && next === "*") {
|
|
24254
|
-
inMultiLineComment = true;
|
|
24255
|
-
i++;
|
|
24256
|
-
continue;
|
|
24257
|
-
}
|
|
24258
|
-
result += ch;
|
|
24259
|
-
}
|
|
24260
|
-
return result;
|
|
25617
|
+
function formattingOptions(source) {
|
|
25618
|
+
const indent = source.match(/(?:^|\r?\n)([\t ]+)"/)?.[1];
|
|
25619
|
+
return {
|
|
25620
|
+
insertSpaces: !indent?.includes("\t"),
|
|
25621
|
+
tabSize: indent && !indent.includes("\t") ? indent.length : 2,
|
|
25622
|
+
eol: source.includes(`\r
|
|
25623
|
+
`) ? `\r
|
|
25624
|
+
` : `
|
|
25625
|
+
`
|
|
25626
|
+
};
|
|
24261
25627
|
}
|
|
24262
|
-
function
|
|
24263
|
-
|
|
24264
|
-
|
|
24265
|
-
|
|
24266
|
-
|
|
24267
|
-
|
|
24268
|
-
|
|
24269
|
-
|
|
24270
|
-
|
|
24271
|
-
if (escaped) {
|
|
24272
|
-
escaped = false;
|
|
24273
|
-
} else if (ch === "\\") {
|
|
24274
|
-
escaped = true;
|
|
24275
|
-
} else if (ch === quote) {
|
|
24276
|
-
inString = false;
|
|
24277
|
-
}
|
|
24278
|
-
continue;
|
|
24279
|
-
}
|
|
24280
|
-
if (ch === '"' || ch === "'") {
|
|
24281
|
-
inString = true;
|
|
24282
|
-
quote = ch;
|
|
24283
|
-
result += ch;
|
|
24284
|
-
continue;
|
|
24285
|
-
}
|
|
24286
|
-
if (ch === ",") {
|
|
24287
|
-
let j = i + 1;
|
|
24288
|
-
while (j < source.length && /\s/.test(source[j])) {
|
|
24289
|
-
j++;
|
|
24290
|
-
}
|
|
24291
|
-
if (source[j] === "}" || source[j] === "]") {
|
|
24292
|
-
continue;
|
|
24293
|
-
}
|
|
24294
|
-
}
|
|
24295
|
-
result += ch;
|
|
24296
|
-
}
|
|
24297
|
-
return result;
|
|
25628
|
+
function writeConfigValue(configPath, path, value) {
|
|
25629
|
+
const raw = readFileSync2(configPath, "utf-8");
|
|
25630
|
+
const hasBom = raw.startsWith("\uFEFF");
|
|
25631
|
+
const source = hasBom ? raw.slice(1) : raw;
|
|
25632
|
+
const edits = modify(source, [...path], value, { formattingOptions: formattingOptions(source) });
|
|
25633
|
+
if (edits.length === 0)
|
|
25634
|
+
return;
|
|
25635
|
+
const updated = applyEdits(source, edits);
|
|
25636
|
+
atomicWriteText(configPath, hasBom ? `\uFEFF${updated}` : updated);
|
|
24298
25637
|
}
|
|
24299
|
-
function
|
|
24300
|
-
const
|
|
24301
|
-
|
|
24302
|
-
|
|
24303
|
-
|
|
24304
|
-
return parsed2;
|
|
24305
|
-
}
|
|
24306
|
-
} catch {}
|
|
24307
|
-
const withoutComments = stripJsonComments(content);
|
|
24308
|
-
const withoutTrailingCommas = stripTrailingCommas(withoutComments);
|
|
24309
|
-
const parsed = JSON.parse(withoutTrailingCommas);
|
|
24310
|
-
if (!isJsonObject(parsed)) {
|
|
24311
|
-
throw new Error("OpenCode config must be a top-level object");
|
|
24312
|
-
}
|
|
24313
|
-
return parsed;
|
|
25638
|
+
function configuredDaemonUrl() {
|
|
25639
|
+
const daemonUrl = readTrimmedEnv("SIGNET_DAEMON_URL");
|
|
25640
|
+
if (!daemonUrl)
|
|
25641
|
+
return;
|
|
25642
|
+
return resolveSignetDaemonUrl({ env: { SIGNET_DAEMON_URL: daemonUrl } });
|
|
24314
25643
|
}
|
|
24315
25644
|
|
|
24316
25645
|
class OpenCodeConnector extends BaseConnector {
|
|
@@ -24326,7 +25655,7 @@ class OpenCodeConnector extends BaseConnector {
|
|
|
24326
25655
|
return candidate;
|
|
24327
25656
|
}
|
|
24328
25657
|
}
|
|
24329
|
-
return join4(opencodePath, "opencode.
|
|
25658
|
+
return join4(opencodePath, "opencode.jsonc");
|
|
24330
25659
|
}
|
|
24331
25660
|
getPluginsPath(opencodePath) {
|
|
24332
25661
|
return join4(opencodePath, "plugins");
|
|
@@ -24334,26 +25663,34 @@ class OpenCodeConnector extends BaseConnector {
|
|
|
24334
25663
|
getPluginFilePath(opencodePath) {
|
|
24335
25664
|
return join4(this.getPluginsPath(opencodePath), "signet.mjs");
|
|
24336
25665
|
}
|
|
25666
|
+
getApiKeyFilePath(opencodePath) {
|
|
25667
|
+
return join4(this.getPluginsPath(opencodePath), API_KEY_FILE_NAME);
|
|
25668
|
+
}
|
|
24337
25669
|
getPluginConfigEntry(opencodePath) {
|
|
24338
25670
|
return `./${relative(opencodePath, this.getPluginFilePath(opencodePath)).replaceAll("\\", "/")}`;
|
|
24339
25671
|
}
|
|
24340
25672
|
async install(basePath) {
|
|
24341
25673
|
const filesWritten = [];
|
|
24342
25674
|
const expandedBasePath = expandHome(basePath || join4(homedir(), ".agents"));
|
|
24343
|
-
const
|
|
24344
|
-
|
|
25675
|
+
const daemonUrl = configuredDaemonUrl();
|
|
25676
|
+
const identityAvailable = hasValidIdentity(expandedBasePath);
|
|
25677
|
+
const identityMode = identityAvailable ? loadIdentityMode(expandedBasePath) : undefined;
|
|
25678
|
+
if (!identityAvailable && !daemonUrl) {
|
|
24345
25679
|
return {
|
|
24346
25680
|
success: false,
|
|
24347
25681
|
message: `No valid Signet identity found at ${expandedBasePath}`,
|
|
24348
25682
|
filesWritten
|
|
24349
25683
|
};
|
|
24350
25684
|
}
|
|
24351
|
-
const strippedAgentsPath = this.stripLegacySignetBlock(expandedBasePath);
|
|
24352
|
-
if (strippedAgentsPath !== null) {
|
|
24353
|
-
filesWritten.push(strippedAgentsPath);
|
|
24354
|
-
}
|
|
24355
25685
|
const opencodePath = this.getOpenCodePath();
|
|
24356
25686
|
const pluginsPath = this.getPluginsPath(opencodePath);
|
|
25687
|
+
this.validateConfigCandidates(opencodePath);
|
|
25688
|
+
if (identityAvailable) {
|
|
25689
|
+
const strippedAgentsPath = this.stripLegacySignetBlock(expandedBasePath);
|
|
25690
|
+
if (strippedAgentsPath !== null) {
|
|
25691
|
+
filesWritten.push(strippedAgentsPath);
|
|
25692
|
+
}
|
|
25693
|
+
}
|
|
24357
25694
|
if (!existsSync2(opencodePath)) {
|
|
24358
25695
|
mkdirSync(opencodePath, { recursive: true });
|
|
24359
25696
|
}
|
|
@@ -24361,8 +25698,17 @@ class OpenCodeConnector extends BaseConnector {
|
|
|
24361
25698
|
mkdirSync(pluginsPath, { recursive: true });
|
|
24362
25699
|
}
|
|
24363
25700
|
this.migrateFromLegacy(opencodePath);
|
|
25701
|
+
const apiKey = readTrimmedEnv("SIGNET_API_KEY") ?? readTrimmedEnv("SIGNET_TOKEN");
|
|
25702
|
+
const apiKeyFilePath = this.getApiKeyFilePath(opencodePath);
|
|
25703
|
+
if (apiKey) {
|
|
25704
|
+
atomicWriteText(apiKeyFilePath, `${apiKey}
|
|
25705
|
+
`, 384);
|
|
25706
|
+
filesWritten.push(apiKeyFilePath);
|
|
25707
|
+
} else if (existsSync2(apiKeyFilePath)) {
|
|
25708
|
+
rmSync(apiKeyFilePath);
|
|
25709
|
+
}
|
|
24364
25710
|
const pluginFilePath = this.getPluginFilePath(opencodePath);
|
|
24365
|
-
writeFileSync2(pluginFilePath, buildPluginBundle());
|
|
25711
|
+
writeFileSync2(pluginFilePath, buildPluginBundle(apiKey ? apiKeyFilePath : undefined));
|
|
24366
25712
|
filesWritten.push(pluginFilePath);
|
|
24367
25713
|
this.ensureConfigFile(opencodePath);
|
|
24368
25714
|
this.registerPlugin(opencodePath);
|
|
@@ -24382,11 +25728,11 @@ class OpenCodeConnector extends BaseConnector {
|
|
|
24382
25728
|
} catch {}
|
|
24383
25729
|
}
|
|
24384
25730
|
}
|
|
24385
|
-
this.registerMcpServer(opencodePath);
|
|
25731
|
+
this.registerMcpServer(opencodePath, daemonUrl, apiKey ? `./plugins/${API_KEY_FILE_NAME}` : undefined);
|
|
24386
25732
|
this.registerPipelineAgent(opencodePath);
|
|
24387
25733
|
const skillsSource = join4(expandedBasePath, "skills");
|
|
24388
25734
|
const skillsDest = join4(opencodePath, "skills");
|
|
24389
|
-
if (existsSync2(skillsSource)) {
|
|
25735
|
+
if (identityAvailable && existsSync2(skillsSource)) {
|
|
24390
25736
|
this.symlinkSkills(skillsSource, skillsDest);
|
|
24391
25737
|
}
|
|
24392
25738
|
return {
|
|
@@ -24403,6 +25749,11 @@ class OpenCodeConnector extends BaseConnector {
|
|
|
24403
25749
|
rmSync(pluginFilePath);
|
|
24404
25750
|
filesRemoved.push(pluginFilePath);
|
|
24405
25751
|
}
|
|
25752
|
+
const apiKeyFilePath = this.getApiKeyFilePath(opencodePath);
|
|
25753
|
+
if (existsSync2(apiKeyFilePath)) {
|
|
25754
|
+
rmSync(apiKeyFilePath);
|
|
25755
|
+
filesRemoved.push(apiKeyFilePath);
|
|
25756
|
+
}
|
|
24406
25757
|
const agentsMdPath = join4(opencodePath, "AGENTS.md");
|
|
24407
25758
|
if (existsSync2(agentsMdPath)) {
|
|
24408
25759
|
try {
|
|
@@ -24438,63 +25789,71 @@ class OpenCodeConnector extends BaseConnector {
|
|
|
24438
25789
|
}
|
|
24439
25790
|
migrateFromLegacy(opencodePath) {
|
|
24440
25791
|
const legacyPluginPath = join4(opencodePath, "memory.mjs");
|
|
24441
|
-
if (existsSync2(legacyPluginPath))
|
|
25792
|
+
if (existsSync2(legacyPluginPath))
|
|
24442
25793
|
rmSync(legacyPluginPath);
|
|
24443
|
-
}
|
|
24444
25794
|
for (const configPath of this.getConfigCandidates(opencodePath)) {
|
|
24445
25795
|
if (!existsSync2(configPath))
|
|
24446
25796
|
continue;
|
|
24447
|
-
|
|
24448
|
-
|
|
24449
|
-
config = parseJsonOrJsonc(readFileSync2(configPath, "utf-8"));
|
|
24450
|
-
} catch {
|
|
25797
|
+
const config = this.readConfigForCleanup(configPath);
|
|
25798
|
+
if (!config)
|
|
24451
25799
|
continue;
|
|
24452
|
-
|
|
24453
|
-
|
|
24454
|
-
|
|
24455
|
-
atomicWriteJson(configPath, config);
|
|
25800
|
+
for (const key of ["plugin", "plugins"]) {
|
|
25801
|
+
const entries = Array.isArray(config[key]) ? config[key] : [];
|
|
25802
|
+
this.removeArrayEntries(configPath, key, entries, (entry) => this.isLegacyPluginEntry(entry));
|
|
24456
25803
|
}
|
|
24457
25804
|
}
|
|
24458
25805
|
}
|
|
24459
|
-
|
|
24460
|
-
|
|
24461
|
-
|
|
24462
|
-
|
|
24463
|
-
|
|
24464
|
-
|
|
24465
|
-
|
|
25806
|
+
readConfig(configPath) {
|
|
25807
|
+
try {
|
|
25808
|
+
return parseJsonOrJsonc(readFileSync2(configPath, "utf-8"));
|
|
25809
|
+
} catch (error) {
|
|
25810
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
25811
|
+
throw new Error(`Cannot update OpenCode config ${configPath}: ${message}`);
|
|
25812
|
+
}
|
|
25813
|
+
}
|
|
25814
|
+
validateConfigCandidates(opencodePath) {
|
|
25815
|
+
for (const configPath of this.getConfigCandidates(opencodePath)) {
|
|
25816
|
+
if (existsSync2(configPath))
|
|
25817
|
+
this.readConfig(configPath);
|
|
25818
|
+
}
|
|
25819
|
+
}
|
|
25820
|
+
readConfigForCleanup(configPath) {
|
|
25821
|
+
try {
|
|
25822
|
+
return this.readConfig(configPath);
|
|
25823
|
+
} catch (error) {
|
|
25824
|
+
console.warn(`[signet] Warning: ${error instanceof Error ? error.message : String(error)}`);
|
|
25825
|
+
return;
|
|
25826
|
+
}
|
|
25827
|
+
}
|
|
25828
|
+
isLegacyPluginEntry(entry) {
|
|
25829
|
+
if (typeof entry !== "string")
|
|
24466
25830
|
return false;
|
|
24467
|
-
|
|
24468
|
-
|
|
24469
|
-
|
|
24470
|
-
|
|
24471
|
-
|
|
24472
|
-
|
|
24473
|
-
|
|
24474
|
-
|
|
24475
|
-
|
|
24476
|
-
|
|
24477
|
-
|
|
25831
|
+
const trimmed = entry.trim();
|
|
25832
|
+
return trimmed === "./memory.mjs" || trimmed === "memory.mjs" || trimmed.endsWith("/memory.mjs");
|
|
25833
|
+
}
|
|
25834
|
+
pluginSpecifier(entry) {
|
|
25835
|
+
if (typeof entry === "string")
|
|
25836
|
+
return entry;
|
|
25837
|
+
if (Array.isArray(entry) && typeof entry[0] === "string")
|
|
25838
|
+
return entry[0];
|
|
25839
|
+
return;
|
|
25840
|
+
}
|
|
25841
|
+
removeArrayEntries(configPath, key, entries, shouldRemove) {
|
|
25842
|
+
for (let index = entries.length - 1;index >= 0; index--) {
|
|
25843
|
+
if (shouldRemove(entries[index]))
|
|
25844
|
+
writeConfigValue(configPath, [key, index], undefined);
|
|
24478
25845
|
}
|
|
24479
|
-
return changed;
|
|
24480
25846
|
}
|
|
24481
25847
|
registerPlugin(opencodePath) {
|
|
24482
25848
|
const pluginEntry = this.getPluginConfigEntry(opencodePath);
|
|
24483
|
-
|
|
24484
|
-
|
|
24485
|
-
|
|
24486
|
-
|
|
24487
|
-
|
|
24488
|
-
|
|
24489
|
-
|
|
24490
|
-
|
|
24491
|
-
}
|
|
24492
|
-
const existing = toStringArray(config.plugin);
|
|
24493
|
-
if (!existing.includes(pluginEntry)) {
|
|
24494
|
-
config.plugin = [...existing, pluginEntry];
|
|
24495
|
-
atomicWriteJson(configPath, config);
|
|
24496
|
-
}
|
|
24497
|
-
return;
|
|
25849
|
+
this.removePlugin(opencodePath);
|
|
25850
|
+
const configPath = this.getConfigPath();
|
|
25851
|
+
const config = this.readConfig(configPath);
|
|
25852
|
+
const entries = Array.isArray(config.plugin) ? config.plugin : [];
|
|
25853
|
+
if (Array.isArray(config.plugin)) {
|
|
25854
|
+
writeConfigValue(configPath, ["plugin", entries.length], pluginEntry);
|
|
25855
|
+
} else {
|
|
25856
|
+
writeConfigValue(configPath, ["plugin"], [pluginEntry]);
|
|
24498
25857
|
}
|
|
24499
25858
|
}
|
|
24500
25859
|
removePlugin(opencodePath) {
|
|
@@ -24502,73 +25861,58 @@ class OpenCodeConnector extends BaseConnector {
|
|
|
24502
25861
|
for (const configPath of this.getConfigCandidates(opencodePath)) {
|
|
24503
25862
|
if (!existsSync2(configPath))
|
|
24504
25863
|
continue;
|
|
24505
|
-
|
|
24506
|
-
|
|
24507
|
-
config = parseJsonOrJsonc(readFileSync2(configPath, "utf-8"));
|
|
24508
|
-
} catch {
|
|
25864
|
+
const config = this.readConfigForCleanup(configPath);
|
|
25865
|
+
if (!config)
|
|
24509
25866
|
continue;
|
|
24510
|
-
|
|
24511
|
-
|
|
24512
|
-
const filtered = existing.filter((entry) => entry !== pluginEntry);
|
|
24513
|
-
if (filtered.length !== existing.length) {
|
|
24514
|
-
config.plugin = filtered;
|
|
24515
|
-
atomicWriteJson(configPath, config);
|
|
24516
|
-
}
|
|
24517
|
-
return;
|
|
25867
|
+
const entries = Array.isArray(config.plugin) ? config.plugin : [];
|
|
25868
|
+
this.removeArrayEntries(configPath, "plugin", entries, (entry) => this.pluginSpecifier(entry) === pluginEntry);
|
|
24518
25869
|
}
|
|
24519
25870
|
}
|
|
24520
|
-
registerMcpServer(opencodePath) {
|
|
24521
|
-
|
|
24522
|
-
|
|
24523
|
-
|
|
24524
|
-
|
|
24525
|
-
|
|
24526
|
-
|
|
24527
|
-
|
|
24528
|
-
|
|
24529
|
-
|
|
24530
|
-
|
|
24531
|
-
|
|
24532
|
-
if (process.platform === "win32") {
|
|
24533
|
-
const cliEntry = process.argv[1] || "";
|
|
24534
|
-
const mcpJs = join4(cliEntry, "..", "..", "dist", "mcp-stdio.js");
|
|
24535
|
-
if (existsSync2(mcpJs)) {
|
|
24536
|
-
mcpCommand = [process.execPath, mcpJs];
|
|
24537
|
-
} else {
|
|
24538
|
-
console.warn(`[signet] Warning: could not resolve mcp-stdio.js from argv[1]="${cliEntry}". ` + `MCP server config will use "signet-mcp" which may fail on Windows without shell:true.`);
|
|
24539
|
-
}
|
|
24540
|
-
}
|
|
24541
|
-
const environment = signetRuntimeEnv();
|
|
24542
|
-
config.mcp = {
|
|
24543
|
-
...existingMcp,
|
|
24544
|
-
signet: {
|
|
24545
|
-
type: "local",
|
|
24546
|
-
command: mcpCommand,
|
|
24547
|
-
...Object.keys(environment).length > 0 ? { environment } : {},
|
|
24548
|
-
enabled: true
|
|
24549
|
-
}
|
|
24550
|
-
};
|
|
24551
|
-
atomicWriteJson(configPath, config);
|
|
25871
|
+
registerMcpServer(opencodePath, daemonUrl, apiKeyFile) {
|
|
25872
|
+
this.removeMcpServer(opencodePath);
|
|
25873
|
+
const configPath = this.getConfigPath();
|
|
25874
|
+
this.readConfig(configPath);
|
|
25875
|
+
if (daemonUrl) {
|
|
25876
|
+
writeConfigValue(configPath, ["mcp", "signet"], {
|
|
25877
|
+
type: "remote",
|
|
25878
|
+
url: `${daemonUrl}/mcp`,
|
|
25879
|
+
...apiKeyFile ? { headers: { Authorization: `Bearer {file:${apiKeyFile}}` } } : {},
|
|
25880
|
+
oauth: false,
|
|
25881
|
+
enabled: true
|
|
25882
|
+
});
|
|
24552
25883
|
return;
|
|
24553
25884
|
}
|
|
25885
|
+
let mcpCommand = ["signet-mcp"];
|
|
25886
|
+
if (process.platform === "win32") {
|
|
25887
|
+
const cliEntry = process.argv[1] || "";
|
|
25888
|
+
const mcpJs = join4(cliEntry, "..", "..", "dist", "mcp-stdio.js");
|
|
25889
|
+
if (existsSync2(mcpJs)) {
|
|
25890
|
+
mcpCommand = [process.execPath, mcpJs];
|
|
25891
|
+
} else {
|
|
25892
|
+
console.warn(`[signet] Warning: could not resolve mcp-stdio.js from argv[1]="${cliEntry}". MCP server config will use "signet-mcp" which may fail on Windows without shell:true.`);
|
|
25893
|
+
}
|
|
25894
|
+
}
|
|
25895
|
+
const environment = signetRuntimeEnv();
|
|
25896
|
+
if (apiKeyFile)
|
|
25897
|
+
environment.SIGNET_API_KEY = `{file:${apiKeyFile}}`;
|
|
25898
|
+
writeConfigValue(configPath, ["mcp", "signet"], {
|
|
25899
|
+
type: "local",
|
|
25900
|
+
command: mcpCommand,
|
|
25901
|
+
...Object.keys(environment).length > 0 ? { environment } : {},
|
|
25902
|
+
enabled: true
|
|
25903
|
+
});
|
|
24554
25904
|
}
|
|
24555
25905
|
removeMcpServer(opencodePath) {
|
|
24556
25906
|
for (const configPath of this.getConfigCandidates(opencodePath)) {
|
|
24557
25907
|
if (!existsSync2(configPath))
|
|
24558
25908
|
continue;
|
|
24559
|
-
|
|
24560
|
-
|
|
24561
|
-
config = parseJsonOrJsonc(readFileSync2(configPath, "utf-8"));
|
|
24562
|
-
} catch {
|
|
25909
|
+
const config = this.readConfigForCleanup(configPath);
|
|
25910
|
+
if (!config || !isJsonObject(config.mcp) || !("signet" in config.mcp))
|
|
24563
25911
|
continue;
|
|
24564
|
-
|
|
24565
|
-
|
|
24566
|
-
|
|
24567
|
-
|
|
24568
|
-
if (Object.keys(mcp).length === 0) {
|
|
24569
|
-
delete config.mcp;
|
|
24570
|
-
}
|
|
24571
|
-
atomicWriteJson(configPath, config);
|
|
25912
|
+
if (Object.keys(config.mcp).length === 1) {
|
|
25913
|
+
writeConfigValue(configPath, ["mcp"], undefined);
|
|
25914
|
+
} else {
|
|
25915
|
+
writeConfigValue(configPath, ["mcp", "signet"], undefined);
|
|
24572
25916
|
}
|
|
24573
25917
|
}
|
|
24574
25918
|
}
|
|
@@ -24580,46 +25924,25 @@ class OpenCodeConnector extends BaseConnector {
|
|
|
24580
25924
|
mode: "all"
|
|
24581
25925
|
};
|
|
24582
25926
|
registerPipelineAgent(opencodePath) {
|
|
24583
|
-
|
|
24584
|
-
|
|
24585
|
-
|
|
24586
|
-
|
|
24587
|
-
|
|
24588
|
-
|
|
24589
|
-
} catch {
|
|
24590
|
-
continue;
|
|
24591
|
-
}
|
|
24592
|
-
const agents = isJsonObject(config.agent) ? { ...config.agent } : {};
|
|
24593
|
-
agents[OPENCODE_PIPELINE_AGENT] = { ...OpenCodeConnector.PIPELINE_AGENT_CONFIG };
|
|
24594
|
-
config.agent = agents;
|
|
24595
|
-
atomicWriteJson(configPath, config);
|
|
24596
|
-
return;
|
|
24597
|
-
}
|
|
25927
|
+
this.removePipelineAgent(opencodePath);
|
|
25928
|
+
const configPath = this.getConfigPath();
|
|
25929
|
+
this.readConfig(configPath);
|
|
25930
|
+
writeConfigValue(configPath, ["agent", OPENCODE_PIPELINE_AGENT], {
|
|
25931
|
+
...OpenCodeConnector.PIPELINE_AGENT_CONFIG
|
|
25932
|
+
});
|
|
24598
25933
|
}
|
|
24599
25934
|
removePipelineAgent(opencodePath) {
|
|
24600
25935
|
for (const configPath of this.getConfigCandidates(opencodePath)) {
|
|
24601
25936
|
if (!existsSync2(configPath))
|
|
24602
25937
|
continue;
|
|
24603
|
-
|
|
24604
|
-
|
|
24605
|
-
config = parseJsonOrJsonc(readFileSync2(configPath, "utf-8"));
|
|
24606
|
-
} catch {
|
|
24607
|
-
continue;
|
|
24608
|
-
}
|
|
24609
|
-
if (!isJsonObject(config.agent))
|
|
24610
|
-
continue;
|
|
24611
|
-
const agents = config.agent;
|
|
24612
|
-
if (!(OPENCODE_PIPELINE_AGENT in agents))
|
|
25938
|
+
const config = this.readConfigForCleanup(configPath);
|
|
25939
|
+
if (!config || !isJsonObject(config.agent) || !(OPENCODE_PIPELINE_AGENT in config.agent))
|
|
24613
25940
|
continue;
|
|
24614
|
-
|
|
24615
|
-
|
|
24616
|
-
const { agent: __, ...configWithoutAgent } = config;
|
|
24617
|
-
atomicWriteJson(configPath, configWithoutAgent);
|
|
25941
|
+
if (Object.keys(config.agent).length === 1) {
|
|
25942
|
+
writeConfigValue(configPath, ["agent"], undefined);
|
|
24618
25943
|
} else {
|
|
24619
|
-
|
|
24620
|
-
atomicWriteJson(configPath, config);
|
|
25944
|
+
writeConfigValue(configPath, ["agent", OPENCODE_PIPELINE_AGENT], undefined);
|
|
24621
25945
|
}
|
|
24622
|
-
return;
|
|
24623
25946
|
}
|
|
24624
25947
|
}
|
|
24625
25948
|
ensureConfigFile(opencodePath) {
|
|
@@ -24628,12 +25951,12 @@ class OpenCodeConnector extends BaseConnector {
|
|
|
24628
25951
|
return;
|
|
24629
25952
|
}
|
|
24630
25953
|
mkdirSync(opencodePath, { recursive: true });
|
|
24631
|
-
atomicWriteJson(join4(opencodePath, "opencode.
|
|
25954
|
+
atomicWriteJson(join4(opencodePath, "opencode.jsonc"), {});
|
|
24632
25955
|
}
|
|
24633
25956
|
getConfigCandidates(opencodePath) {
|
|
24634
25957
|
return [
|
|
24635
|
-
join4(opencodePath, "opencode.json"),
|
|
24636
25958
|
join4(opencodePath, "opencode.jsonc"),
|
|
25959
|
+
join4(opencodePath, "opencode.json"),
|
|
24637
25960
|
join4(opencodePath, "config.json")
|
|
24638
25961
|
];
|
|
24639
25962
|
}
|