sphica 0.6.30 → 0.6.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +2 -2
- package/THIRD_PARTY_NOTICES.md +33 -0
- package/dist/capture.js +267 -0
- package/dist/cli.js +1229 -15
- package/dist/deliver.js +267 -0
- package/dist/mcp-record.js +267 -0
- package/dist/mcp.js +269 -0
- package/hooks/codex.json +9 -9
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3007,11 +3007,1114 @@ import os from "node:os";
|
|
|
3007
3007
|
import path2 from "node:path";
|
|
3008
3008
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3009
3009
|
|
|
3010
|
+
// server/src/codex-trust.ts
|
|
3011
|
+
import crypto from "node:crypto";
|
|
3012
|
+
|
|
3013
|
+
// server/node_modules/smol-toml/dist/error.js
|
|
3014
|
+
/*!
|
|
3015
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3016
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
3017
|
+
*
|
|
3018
|
+
* Redistribution and use in source and binary forms, with or without
|
|
3019
|
+
* modification, are permitted provided that the following conditions are met:
|
|
3020
|
+
*
|
|
3021
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
3022
|
+
* list of conditions and the following disclaimer.
|
|
3023
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
3024
|
+
* this list of conditions and the following disclaimer in the
|
|
3025
|
+
* documentation and/or other materials provided with the distribution.
|
|
3026
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
3027
|
+
* may be used to endorse or promote products derived from this software without
|
|
3028
|
+
* specific prior written permission.
|
|
3029
|
+
*
|
|
3030
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
3031
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
3032
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
3033
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
3034
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
3035
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
3036
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
3037
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
3038
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
3039
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3040
|
+
*/
|
|
3041
|
+
function getLineColFromPtr(string, ptr) {
|
|
3042
|
+
let lines = string.slice(0, ptr).split(/\r?\n/);
|
|
3043
|
+
return [lines.length, lines.pop().length + 1];
|
|
3044
|
+
}
|
|
3045
|
+
function makeCodeBlock(string, line, column) {
|
|
3046
|
+
let lines = string.split(/\r?\n/);
|
|
3047
|
+
let codeblock = "";
|
|
3048
|
+
let numberLen = (Math.log10(line + 1) | 0) + 1;
|
|
3049
|
+
for (let i2 = line - 1;i2 <= line + 1; i2++) {
|
|
3050
|
+
let l = lines[i2 - 1];
|
|
3051
|
+
if (!l)
|
|
3052
|
+
continue;
|
|
3053
|
+
codeblock += i2.toString().padEnd(numberLen, " ");
|
|
3054
|
+
codeblock += ": ";
|
|
3055
|
+
codeblock += l;
|
|
3056
|
+
codeblock += `
|
|
3057
|
+
`;
|
|
3058
|
+
if (i2 === line) {
|
|
3059
|
+
codeblock += " ".repeat(numberLen + column + 2);
|
|
3060
|
+
codeblock += `^
|
|
3061
|
+
`;
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
return codeblock;
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
class TomlError extends Error {
|
|
3068
|
+
line;
|
|
3069
|
+
column;
|
|
3070
|
+
codeblock;
|
|
3071
|
+
constructor(message, options) {
|
|
3072
|
+
const [line, column] = getLineColFromPtr(options.toml, options.ptr);
|
|
3073
|
+
const codeblock = makeCodeBlock(options.toml, line, column);
|
|
3074
|
+
super(`Invalid TOML document: ${message}
|
|
3075
|
+
|
|
3076
|
+
${codeblock}`, options);
|
|
3077
|
+
this.line = line;
|
|
3078
|
+
this.column = column;
|
|
3079
|
+
this.codeblock = codeblock;
|
|
3080
|
+
}
|
|
3081
|
+
static x(message, ctx, ptr) {
|
|
3082
|
+
throw new TomlError(message, { toml: ctx.s, ptr: ptr ?? ctx.p });
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
|
|
3086
|
+
// server/node_modules/smol-toml/dist/primitive.js
|
|
3087
|
+
/*!
|
|
3088
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3089
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
3090
|
+
*
|
|
3091
|
+
* Redistribution and use in source and binary forms, with or without
|
|
3092
|
+
* modification, are permitted provided that the following conditions are met:
|
|
3093
|
+
*
|
|
3094
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
3095
|
+
* list of conditions and the following disclaimer.
|
|
3096
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
3097
|
+
* this list of conditions and the following disclaimer in the
|
|
3098
|
+
* documentation and/or other materials provided with the distribution.
|
|
3099
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
3100
|
+
* may be used to endorse or promote products derived from this software without
|
|
3101
|
+
* specific prior written permission.
|
|
3102
|
+
*
|
|
3103
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
3104
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
3105
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
3106
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
3107
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
3108
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
3109
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
3110
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
3111
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
3112
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3113
|
+
*/
|
|
3114
|
+
function parseString(ctx) {
|
|
3115
|
+
let startPtr = ctx.p;
|
|
3116
|
+
let c = ctx.s.charCodeAt(ctx.p++);
|
|
3117
|
+
let first = c;
|
|
3118
|
+
let isLiteral = c === 39;
|
|
3119
|
+
let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
|
|
3120
|
+
if (isMultiline) {
|
|
3121
|
+
if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 10)
|
|
3122
|
+
ctx.p++;
|
|
3123
|
+
else if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)
|
|
3124
|
+
ctx.p += 2;
|
|
3125
|
+
}
|
|
3126
|
+
let parsed = "";
|
|
3127
|
+
let sliceStart = ctx.p;
|
|
3128
|
+
let state = 0;
|
|
3129
|
+
for (;ctx.p < ctx.s.length; ctx.p++) {
|
|
3130
|
+
c = ctx.s.charCodeAt(ctx.p);
|
|
3131
|
+
if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) {
|
|
3132
|
+
state = state && 3;
|
|
3133
|
+
} else if (c < 32 && c !== 9 || c === 127) {
|
|
3134
|
+
TomlError.x("control characters are not allowed in strings", ctx);
|
|
3135
|
+
} else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
|
|
3136
|
+
if (isMultiline) {
|
|
3137
|
+
if (ctx.s.charCodeAt(ctx.p + 3) === first)
|
|
3138
|
+
ctx.p++;
|
|
3139
|
+
if (ctx.s.charCodeAt(ctx.p + 3) === first)
|
|
3140
|
+
ctx.p++;
|
|
3141
|
+
}
|
|
3142
|
+
if (!state) {
|
|
3143
|
+
let s = ctx.s.slice(sliceStart, ctx.p);
|
|
3144
|
+
parsed = parsed ? parsed + s : s;
|
|
3145
|
+
}
|
|
3146
|
+
ctx.p += isMultiline ? 3 : 1;
|
|
3147
|
+
return parsed;
|
|
3148
|
+
} else if (!state) {
|
|
3149
|
+
if (!isLiteral && c === 92) {
|
|
3150
|
+
parsed += ctx.s.slice(sliceStart, sliceStart = ctx.p);
|
|
3151
|
+
state = 1;
|
|
3152
|
+
}
|
|
3153
|
+
} else if (state === 1) {
|
|
3154
|
+
if (c === 120 || c === 117 || c === 85) {
|
|
3155
|
+
let errPtr = ctx.p++ - 1;
|
|
3156
|
+
let value = 0;
|
|
3157
|
+
let len = c === 120 ? 2 : c === 117 ? 4 : 8;
|
|
3158
|
+
for (let j = 0;j < len; j++, ctx.p++) {
|
|
3159
|
+
let hex = ctx.s.charCodeAt(ctx.p);
|
|
3160
|
+
let digit = hex >= 48 && hex <= 57 ? hex - 48 : hex >= 65 && hex <= 70 ? hex - 65 + 10 : hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1;
|
|
3161
|
+
if (digit < 0)
|
|
3162
|
+
TomlError.x("invalid non-hex character in unicode escape", ctx);
|
|
3163
|
+
value = value << 4 | digit;
|
|
3164
|
+
}
|
|
3165
|
+
if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) {
|
|
3166
|
+
TomlError.x("invalid unicode escape", ctx, errPtr);
|
|
3167
|
+
}
|
|
3168
|
+
parsed += String.fromCodePoint(value);
|
|
3169
|
+
sliceStart = ctx.p--;
|
|
3170
|
+
state = 0;
|
|
3171
|
+
} else if (isMultiline && (c === 32 || c === 9)) {
|
|
3172
|
+
state = 2;
|
|
3173
|
+
} else {
|
|
3174
|
+
if (c === 98)
|
|
3175
|
+
parsed += "\b";
|
|
3176
|
+
else if (c === 116)
|
|
3177
|
+
parsed += "\t";
|
|
3178
|
+
else if (c === 110)
|
|
3179
|
+
parsed += `
|
|
3180
|
+
`;
|
|
3181
|
+
else if (c === 102)
|
|
3182
|
+
parsed += "\f";
|
|
3183
|
+
else if (c === 114)
|
|
3184
|
+
parsed += "\r";
|
|
3185
|
+
else if (c === 101)
|
|
3186
|
+
parsed += "\x1B";
|
|
3187
|
+
else if (c === 34)
|
|
3188
|
+
parsed += '"';
|
|
3189
|
+
else if (c === 92)
|
|
3190
|
+
parsed += "\\";
|
|
3191
|
+
else
|
|
3192
|
+
TomlError.x("unrecognised escape sequence", ctx);
|
|
3193
|
+
sliceStart = ctx.p + 1;
|
|
3194
|
+
state = 0;
|
|
3195
|
+
}
|
|
3196
|
+
} else if (c !== 32 && c !== 9) {
|
|
3197
|
+
if (state === 2)
|
|
3198
|
+
TomlError.x("invalid escape: only line-ending whitespace may be escaped", ctx, sliceStart);
|
|
3199
|
+
state = !isLiteral && c === 92 ? 1 : 0;
|
|
3200
|
+
sliceStart = ctx.p;
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
TomlError.x("unfinished string", ctx, startPtr);
|
|
3204
|
+
}
|
|
3205
|
+
|
|
3206
|
+
// server/node_modules/smol-toml/dist/date.js
|
|
3207
|
+
/*!
|
|
3208
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3209
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
3210
|
+
*
|
|
3211
|
+
* Redistribution and use in source and binary forms, with or without
|
|
3212
|
+
* modification, are permitted provided that the following conditions are met:
|
|
3213
|
+
*
|
|
3214
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
3215
|
+
* list of conditions and the following disclaimer.
|
|
3216
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
3217
|
+
* this list of conditions and the following disclaimer in the
|
|
3218
|
+
* documentation and/or other materials provided with the distribution.
|
|
3219
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
3220
|
+
* may be used to endorse or promote products derived from this software without
|
|
3221
|
+
* specific prior written permission.
|
|
3222
|
+
*
|
|
3223
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
3224
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
3225
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
3226
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
3227
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
3228
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
3229
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
3230
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
3231
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
3232
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3233
|
+
*/
|
|
3234
|
+
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
|
|
3235
|
+
|
|
3236
|
+
class TomlDate extends Date {
|
|
3237
|
+
#hasDate = false;
|
|
3238
|
+
#hasTime = false;
|
|
3239
|
+
#offset = null;
|
|
3240
|
+
constructor(date, fasttype, unsafeDelim) {
|
|
3241
|
+
let hasDate = true;
|
|
3242
|
+
let hasTime = true;
|
|
3243
|
+
let offset = "Z";
|
|
3244
|
+
let c;
|
|
3245
|
+
if (typeof date === "string") {
|
|
3246
|
+
if (fasttype)
|
|
3247
|
+
prep: {
|
|
3248
|
+
if (fasttype < 3) {
|
|
3249
|
+
if (+date.slice(11, 13) > 23) {
|
|
3250
|
+
date = "";
|
|
3251
|
+
break prep;
|
|
3252
|
+
}
|
|
3253
|
+
if (fasttype === 2) {
|
|
3254
|
+
offset = null;
|
|
3255
|
+
date += "Z";
|
|
3256
|
+
} else if ((c = date.charCodeAt(date.length - 1)) !== 90 && c !== 122) {
|
|
3257
|
+
offset = date.slice(date.length - 6);
|
|
3258
|
+
}
|
|
3259
|
+
if (unsafeDelim)
|
|
3260
|
+
date = date.slice(0, 10) + "T" + date.slice(11);
|
|
3261
|
+
} else if (fasttype === 4) {
|
|
3262
|
+
date = +date.slice(0, 2) > 23 ? "" : `0000-01-01T${date}Z`;
|
|
3263
|
+
}
|
|
3264
|
+
hasDate = fasttype !== 4;
|
|
3265
|
+
hasTime = fasttype !== 3;
|
|
3266
|
+
}
|
|
3267
|
+
else {
|
|
3268
|
+
let match = date.match(DATE_TIME_RE);
|
|
3269
|
+
if (match) {
|
|
3270
|
+
if (!match[1]) {
|
|
3271
|
+
hasDate = false;
|
|
3272
|
+
date = `0000-01-01T${date}`;
|
|
3273
|
+
}
|
|
3274
|
+
hasTime = !!match[2];
|
|
3275
|
+
hasTime && date[10] === " " && (date = date.replace(" ", "T"));
|
|
3276
|
+
if (match[2] && +match[2] > 23) {
|
|
3277
|
+
date = "";
|
|
3278
|
+
} else {
|
|
3279
|
+
offset = match[3] || null;
|
|
3280
|
+
if (!offset && hasTime)
|
|
3281
|
+
date += "Z";
|
|
3282
|
+
}
|
|
3283
|
+
} else {
|
|
3284
|
+
date = "";
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
super(date);
|
|
3289
|
+
if (!isNaN(this.getTime())) {
|
|
3290
|
+
this.#hasDate = hasDate;
|
|
3291
|
+
this.#hasTime = hasTime;
|
|
3292
|
+
this.#offset = offset;
|
|
3293
|
+
}
|
|
3294
|
+
}
|
|
3295
|
+
isDateTime() {
|
|
3296
|
+
return this.#hasDate && this.#hasTime;
|
|
3297
|
+
}
|
|
3298
|
+
isLocal() {
|
|
3299
|
+
return !this.#hasDate || !this.#hasTime || !this.#offset;
|
|
3300
|
+
}
|
|
3301
|
+
isDate() {
|
|
3302
|
+
return this.#hasDate && !this.#hasTime;
|
|
3303
|
+
}
|
|
3304
|
+
isTime() {
|
|
3305
|
+
return this.#hasTime && !this.#hasDate;
|
|
3306
|
+
}
|
|
3307
|
+
isValid() {
|
|
3308
|
+
return this.#hasDate || this.#hasTime;
|
|
3309
|
+
}
|
|
3310
|
+
toISOString() {
|
|
3311
|
+
let iso = super.toISOString();
|
|
3312
|
+
if (this.isDate())
|
|
3313
|
+
return iso.slice(0, 10);
|
|
3314
|
+
if (this.isTime())
|
|
3315
|
+
return iso.slice(11, 23);
|
|
3316
|
+
if (this.#offset === null)
|
|
3317
|
+
return iso.slice(0, -1);
|
|
3318
|
+
if (this.#offset === "Z" || this.#offset === "z")
|
|
3319
|
+
return iso;
|
|
3320
|
+
let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
|
|
3321
|
+
offset = this.#offset[0] === "-" ? offset : -offset;
|
|
3322
|
+
let offsetDate = new Date(this.getTime() - offset * 60000);
|
|
3323
|
+
return offsetDate.toISOString().slice(0, -1) + this.#offset;
|
|
3324
|
+
}
|
|
3325
|
+
static wrapAsOffsetDateTime(jsDate, offset = "Z") {
|
|
3326
|
+
let date = new TomlDate(jsDate);
|
|
3327
|
+
date.#offset = offset;
|
|
3328
|
+
return date;
|
|
3329
|
+
}
|
|
3330
|
+
static wrapAsLocalDateTime(jsDate) {
|
|
3331
|
+
let date = new TomlDate(jsDate);
|
|
3332
|
+
date.#offset = null;
|
|
3333
|
+
return date;
|
|
3334
|
+
}
|
|
3335
|
+
static wrapAsLocalDate(jsDate) {
|
|
3336
|
+
let date = new TomlDate(jsDate);
|
|
3337
|
+
date.#hasTime = false;
|
|
3338
|
+
date.#offset = null;
|
|
3339
|
+
return date;
|
|
3340
|
+
}
|
|
3341
|
+
static wrapAsLocalTime(jsDate) {
|
|
3342
|
+
let date = new TomlDate(jsDate);
|
|
3343
|
+
date.#hasDate = false;
|
|
3344
|
+
date.#offset = null;
|
|
3345
|
+
return date;
|
|
3346
|
+
}
|
|
3347
|
+
}
|
|
3348
|
+
|
|
3349
|
+
// server/node_modules/smol-toml/dist/extract.js
|
|
3350
|
+
/*!
|
|
3351
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3352
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
3353
|
+
*
|
|
3354
|
+
* Redistribution and use in source and binary forms, with or without
|
|
3355
|
+
* modification, are permitted provided that the following conditions are met:
|
|
3356
|
+
*
|
|
3357
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
3358
|
+
* list of conditions and the following disclaimer.
|
|
3359
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
3360
|
+
* this list of conditions and the following disclaimer in the
|
|
3361
|
+
* documentation and/or other materials provided with the distribution.
|
|
3362
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
3363
|
+
* may be used to endorse or promote products derived from this software without
|
|
3364
|
+
* specific prior written permission.
|
|
3365
|
+
*
|
|
3366
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
3367
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
3368
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
3369
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
3370
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
3371
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
3372
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
3373
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
3374
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
3375
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3376
|
+
*/
|
|
3377
|
+
function isDigit(char, base = 10) {
|
|
3378
|
+
return base === 16 ? char > 47 && char < 58 || char > 64 && char < 71 || char > 96 && char < 103 : char > 47 && char < 48 + base;
|
|
3379
|
+
}
|
|
3380
|
+
function isEndOfValue(char, delim) {
|
|
3381
|
+
return char === 32 || char === 9 || char === 10 || char === 13 || delim && (char === delim || char === 44) || char === 35;
|
|
3382
|
+
}
|
|
3383
|
+
function extractValue(ctx, end) {
|
|
3384
|
+
let errPtr = ctx.p;
|
|
3385
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
3386
|
+
if (c === 91 || c === 123) {
|
|
3387
|
+
ctx.d-- || TomlError.x("document contains excessively nested structures. aborting.", ctx);
|
|
3388
|
+
let value = c === 91 ? parseArray(ctx) : parseInlineTable(ctx);
|
|
3389
|
+
ctx.d++;
|
|
3390
|
+
return value;
|
|
3391
|
+
}
|
|
3392
|
+
if (c === 34 || c === 39) {
|
|
3393
|
+
return parseString(ctx);
|
|
3394
|
+
}
|
|
3395
|
+
if (c === 116) {
|
|
3396
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101)
|
|
3397
|
+
TomlError.x("invalid value", ctx, errPtr);
|
|
3398
|
+
return ctx.p++, true;
|
|
3399
|
+
}
|
|
3400
|
+
if (c === 102) {
|
|
3401
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101)
|
|
3402
|
+
TomlError.x("invalid value", ctx, errPtr);
|
|
3403
|
+
return ctx.p++, false;
|
|
3404
|
+
}
|
|
3405
|
+
if (c === 43 || c === 45) {
|
|
3406
|
+
return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 44 - c, end);
|
|
3407
|
+
}
|
|
3408
|
+
if (ctx.s.charCodeAt(ctx.p + 4) === 45 && ctx.s.charCodeAt(ctx.p + 7) === 45) {
|
|
3409
|
+
return parseDate(ctx, c, end);
|
|
3410
|
+
}
|
|
3411
|
+
if (ctx.s.charCodeAt(ctx.p + 2) === 58) {
|
|
3412
|
+
return parseTime(ctx, c, end);
|
|
3413
|
+
}
|
|
3414
|
+
return parseNumber(ctx, ctx.p, c, 0, end);
|
|
3415
|
+
}
|
|
3416
|
+
function parseNumber(ctx, startPtr, startChr, sign, endChr) {
|
|
3417
|
+
let c = startChr;
|
|
3418
|
+
let state = 0;
|
|
3419
|
+
let hasUnderscores = false;
|
|
3420
|
+
if (c === 105) {
|
|
3421
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 110 || ctx.s.charCodeAt(++ctx.p) !== 102)
|
|
3422
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
3423
|
+
return ctx.p++, (sign || 1) / 0;
|
|
3424
|
+
}
|
|
3425
|
+
if (c === 110) {
|
|
3426
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 110)
|
|
3427
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
3428
|
+
return ctx.p++, NaN;
|
|
3429
|
+
}
|
|
3430
|
+
if (c === 48) {
|
|
3431
|
+
if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr))
|
|
3432
|
+
return ctx.bi === true ? 0n : 0;
|
|
3433
|
+
if (!sign) {
|
|
3434
|
+
if (c === 120)
|
|
3435
|
+
return parseIntegerBaseN(ctx, startPtr, 16, endChr);
|
|
3436
|
+
else if (c === 98)
|
|
3437
|
+
return parseIntegerBaseN(ctx, startPtr, 2, endChr);
|
|
3438
|
+
else if (c === 111)
|
|
3439
|
+
return parseIntegerBaseN(ctx, startPtr, 8, endChr);
|
|
3440
|
+
}
|
|
3441
|
+
if (c === 46)
|
|
3442
|
+
state = 2;
|
|
3443
|
+
else if (c === 101 || c === 69)
|
|
3444
|
+
state = 4;
|
|
3445
|
+
else
|
|
3446
|
+
TomlError.x("illegal leading zero", ctx, startPtr);
|
|
3447
|
+
} else if (!isDigit(c))
|
|
3448
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
3449
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
3450
|
+
if (!state)
|
|
3451
|
+
state = 1;
|
|
3452
|
+
if (c === 95) {
|
|
3453
|
+
if (!(state & 1))
|
|
3454
|
+
TomlError.x("illegal underscore", ctx);
|
|
3455
|
+
state += 11;
|
|
3456
|
+
hasUnderscores = true;
|
|
3457
|
+
} else if (state === 1 && c === 46)
|
|
3458
|
+
state = 2;
|
|
3459
|
+
else if ((state === 1 || state === 3) && (c === 101 || c === 69))
|
|
3460
|
+
state = 4;
|
|
3461
|
+
else if (state === 4 && (c === 43 || c === 45)) {} else if (!isDigit(c))
|
|
3462
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
3463
|
+
else if (state > 9)
|
|
3464
|
+
state -= 11;
|
|
3465
|
+
else if (!(state & 1))
|
|
3466
|
+
state++;
|
|
3467
|
+
}
|
|
3468
|
+
if (!state) {
|
|
3469
|
+
let val = (startChr - 48) * (sign || 1);
|
|
3470
|
+
return ctx.bi === true ? BigInt(val) : val;
|
|
3471
|
+
}
|
|
3472
|
+
if (!(state & 1))
|
|
3473
|
+
TomlError.x("unfinished numeric value", ctx, startPtr);
|
|
3474
|
+
let str = ctx.s.slice(startPtr, ctx.p);
|
|
3475
|
+
if (hasUnderscores)
|
|
3476
|
+
str = str.replaceAll("_", "");
|
|
3477
|
+
return state > 1 ? parseFloat(str) : parseInteger(ctx, str, 10, startPtr);
|
|
3478
|
+
}
|
|
3479
|
+
function parseIntegerBaseN(ctx, startPtr, base, endChr) {
|
|
3480
|
+
let c, underscore = 1;
|
|
3481
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
3482
|
+
if (c === 95) {
|
|
3483
|
+
if (underscore & 1)
|
|
3484
|
+
TomlError.x("illegal underscore", ctx);
|
|
3485
|
+
underscore = 3;
|
|
3486
|
+
} else if (!isDigit(c, base))
|
|
3487
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
3488
|
+
else if (underscore & 1)
|
|
3489
|
+
underscore--;
|
|
3490
|
+
}
|
|
3491
|
+
if (underscore & 1)
|
|
3492
|
+
TomlError.x("unfinished numeric value", ctx);
|
|
3493
|
+
let str = ctx.s.slice(startPtr + 2, ctx.p);
|
|
3494
|
+
if (underscore)
|
|
3495
|
+
str = str.replaceAll("_", "");
|
|
3496
|
+
return parseInteger(ctx, str, base, startPtr);
|
|
3497
|
+
}
|
|
3498
|
+
function parseInteger(ctx, str, base, startPtr) {
|
|
3499
|
+
if (ctx.bi !== true)
|
|
3500
|
+
int: {
|
|
3501
|
+
let val = parseInt(str, base);
|
|
3502
|
+
if (!Number.isSafeInteger(val)) {
|
|
3503
|
+
if (ctx.bi)
|
|
3504
|
+
break int;
|
|
3505
|
+
TomlError.x("integer value cannot be represented losslessly", ctx, startPtr);
|
|
3506
|
+
}
|
|
3507
|
+
return val;
|
|
3508
|
+
}
|
|
3509
|
+
return base === 10 ? BigInt(str) : BigInt((base === 2 ? "0b" : base === 8 ? "0o" : "0x") + str);
|
|
3510
|
+
}
|
|
3511
|
+
function parseDate(ctx, c, endChr) {
|
|
3512
|
+
let startPtr = ctx.p++, unsafeSeparator;
|
|
3513
|
+
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++))) {
|
|
3514
|
+
return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
|
|
3515
|
+
}
|
|
3516
|
+
ctx.p += 5;
|
|
3517
|
+
if (!isDigit(ctx.s.charCodeAt(ctx.p++)))
|
|
3518
|
+
TomlError.x("invalid date-time: date part is malformed", ctx, startPtr);
|
|
3519
|
+
if (ctx.p >= ctx.s.length || ((c = ctx.s.charCodeAt(ctx.p)) !== 32 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 84 && c !== 116) {
|
|
3520
|
+
let t3 = ctx.s.slice(startPtr, ctx.p);
|
|
3521
|
+
return readDate(ctx, t3, 3, false, startPtr);
|
|
3522
|
+
}
|
|
3523
|
+
if (ctx.s.charCodeAt(ctx.p += 3) !== 58)
|
|
3524
|
+
TomlError.x("invalid date-time: time part is malformed", ctx, startPtr);
|
|
3525
|
+
if (ctx.s.charCodeAt(ctx.p += 3) === 58)
|
|
3526
|
+
ctx.p += 3;
|
|
3527
|
+
if (ctx.s.charCodeAt(ctx.p) === 46)
|
|
3528
|
+
while (isDigit(ctx.s.charCodeAt(++ctx.p)))
|
|
3529
|
+
;
|
|
3530
|
+
if (c = ctx.s.charCodeAt(ctx.p)) {
|
|
3531
|
+
if (c === 90 || c === 122) {
|
|
3532
|
+
let t3 = ctx.s.slice(startPtr, ++ctx.p);
|
|
3533
|
+
return readDate(ctx, t3, 1, unsafeSeparator, startPtr, "[+00:00]");
|
|
3534
|
+
}
|
|
3535
|
+
if (c === 43 || c === 45) {
|
|
3536
|
+
let t3 = ctx.s.slice(startPtr, ctx.p += 6);
|
|
3537
|
+
return readDate(ctx, t3, 1, unsafeSeparator, startPtr, !ctx.ld && "[" + ctx.s.slice(ctx.p - 6, ctx.p) + "]");
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
let t2 = ctx.s.slice(startPtr, ctx.p);
|
|
3541
|
+
return readDate(ctx, t2, 2, unsafeSeparator, startPtr);
|
|
3542
|
+
}
|
|
3543
|
+
function parseTime(ctx, c, endChr) {
|
|
3544
|
+
let start = ctx.p;
|
|
3545
|
+
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(++ctx.p))) {
|
|
3546
|
+
return parseNumber(ctx, --ctx.p, c, 0, endChr);
|
|
3547
|
+
}
|
|
3548
|
+
if (ctx.s.charCodeAt(ctx.p += 4) === 58)
|
|
3549
|
+
ctx.p += 3;
|
|
3550
|
+
if (ctx.s.charCodeAt(ctx.p) === 46)
|
|
3551
|
+
while (isDigit(ctx.s.charCodeAt(++ctx.p)))
|
|
3552
|
+
;
|
|
3553
|
+
let t2 = ctx.s.slice(start, ctx.p);
|
|
3554
|
+
return readDate(ctx, t2, 4, false, start);
|
|
3555
|
+
}
|
|
3556
|
+
function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
|
|
3557
|
+
if (ctx.ld) {
|
|
3558
|
+
let date = new TomlDate(str, type, unsafeDelim);
|
|
3559
|
+
if (!date.isValid())
|
|
3560
|
+
TomlError.x("invalid date", ctx, errPtr);
|
|
3561
|
+
return date;
|
|
3562
|
+
}
|
|
3563
|
+
try {
|
|
3564
|
+
if (temporalSuffix)
|
|
3565
|
+
str += temporalSuffix;
|
|
3566
|
+
switch (type) {
|
|
3567
|
+
case 1:
|
|
3568
|
+
return Temporal.ZonedDateTime.from(str);
|
|
3569
|
+
case 2:
|
|
3570
|
+
return Temporal.PlainDateTime.from(str);
|
|
3571
|
+
case 3:
|
|
3572
|
+
return Temporal.PlainDate.from(str);
|
|
3573
|
+
case 4:
|
|
3574
|
+
return Temporal.PlainTime.from(str);
|
|
3575
|
+
}
|
|
3576
|
+
} catch (e) {
|
|
3577
|
+
TomlError.x(e instanceof Error ? e.message : "" + e, ctx, errPtr);
|
|
3578
|
+
}
|
|
3579
|
+
}
|
|
3580
|
+
|
|
3581
|
+
// server/node_modules/smol-toml/dist/util.js
|
|
3582
|
+
/*!
|
|
3583
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3584
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
3585
|
+
*
|
|
3586
|
+
* Redistribution and use in source and binary forms, with or without
|
|
3587
|
+
* modification, are permitted provided that the following conditions are met:
|
|
3588
|
+
*
|
|
3589
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
3590
|
+
* list of conditions and the following disclaimer.
|
|
3591
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
3592
|
+
* this list of conditions and the following disclaimer in the
|
|
3593
|
+
* documentation and/or other materials provided with the distribution.
|
|
3594
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
3595
|
+
* may be used to endorse or promote products derived from this software without
|
|
3596
|
+
* specific prior written permission.
|
|
3597
|
+
*
|
|
3598
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
3599
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
3600
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
3601
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
3602
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
3603
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
3604
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
3605
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
3606
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
3607
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3608
|
+
*/
|
|
3609
|
+
function skipComment(ctx) {
|
|
3610
|
+
for (;ctx.p < ctx.s.length; ctx.p++) {
|
|
3611
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
3612
|
+
if (c === 10)
|
|
3613
|
+
break;
|
|
3614
|
+
if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
|
|
3615
|
+
ctx.p++;
|
|
3616
|
+
break;
|
|
3617
|
+
}
|
|
3618
|
+
if (c < 32 && c !== 9 || c === 127) {
|
|
3619
|
+
TomlError.x("control characters are not allowed in comments", ctx);
|
|
3620
|
+
}
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3623
|
+
function skipVoid(ctx, banNewLines, banComments) {
|
|
3624
|
+
let c;
|
|
3625
|
+
while (ctx.p < ctx.s.length) {
|
|
3626
|
+
while (ctx.p < ctx.s.length && ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)))
|
|
3627
|
+
ctx.p++;
|
|
3628
|
+
if (banComments || c !== 35)
|
|
3629
|
+
break;
|
|
3630
|
+
skipComment(ctx);
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
|
|
3634
|
+
// server/node_modules/smol-toml/dist/struct.js
|
|
3635
|
+
/*!
|
|
3636
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3637
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
3638
|
+
*
|
|
3639
|
+
* Redistribution and use in source and binary forms, with or without
|
|
3640
|
+
* modification, are permitted provided that the following conditions are met:
|
|
3641
|
+
*
|
|
3642
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
3643
|
+
* list of conditions and the following disclaimer.
|
|
3644
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
3645
|
+
* this list of conditions and the following disclaimer in the
|
|
3646
|
+
* documentation and/or other materials provided with the distribution.
|
|
3647
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
3648
|
+
* may be used to endorse or promote products derived from this software without
|
|
3649
|
+
* specific prior written permission.
|
|
3650
|
+
*
|
|
3651
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
3652
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
3653
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
3654
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
3655
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
3656
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
3657
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
3658
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
3659
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
3660
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3661
|
+
*/
|
|
3662
|
+
function parseKey(ctx, end = 61) {
|
|
3663
|
+
let startPtr;
|
|
3664
|
+
let state = 0;
|
|
3665
|
+
let parsed = [];
|
|
3666
|
+
let sliceStart;
|
|
3667
|
+
let c = ctx.s.charCodeAt(startPtr = ctx.p);
|
|
3668
|
+
do {
|
|
3669
|
+
if (c === end) {
|
|
3670
|
+
if (!state)
|
|
3671
|
+
TomlError.x("unexpected end of key", ctx);
|
|
3672
|
+
if (state === 1)
|
|
3673
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
3674
|
+
return ctx.p++, parsed;
|
|
3675
|
+
} else if (c === 46) {
|
|
3676
|
+
if (!state)
|
|
3677
|
+
TomlError.x("illegal empty bare key", ctx);
|
|
3678
|
+
if (state === 1)
|
|
3679
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
3680
|
+
state = 0;
|
|
3681
|
+
} else if (!state && (c === 34 || c === 39)) {
|
|
3682
|
+
if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2))
|
|
3683
|
+
TomlError.x("illegal quoted key: multiline strings are not allowed", ctx);
|
|
3684
|
+
parsed.push(parseString(ctx));
|
|
3685
|
+
state = 2;
|
|
3686
|
+
ctx.p--;
|
|
3687
|
+
} else if (c === 32 || c === 9) {
|
|
3688
|
+
if (state === 1) {
|
|
3689
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
3690
|
+
state = 2;
|
|
3691
|
+
}
|
|
3692
|
+
} else if (state === 2 || c < 48 && c !== 45 || c > 57 && c < 65 || c > 90 && c < 97 && c !== 95 || c > 122) {
|
|
3693
|
+
TomlError.x("illegal character in key", ctx);
|
|
3694
|
+
} else if (!state) {
|
|
3695
|
+
state = 1;
|
|
3696
|
+
sliceStart = ctx.p;
|
|
3697
|
+
}
|
|
3698
|
+
} while (c = ctx.s.charCodeAt(++ctx.p));
|
|
3699
|
+
TomlError.x("incomplete key-value: cannot find end of key", ctx, startPtr);
|
|
3700
|
+
}
|
|
3701
|
+
function parseInlineTable(ctx) {
|
|
3702
|
+
let startPtr = ctx.p++;
|
|
3703
|
+
let res = Object.create(null);
|
|
3704
|
+
let seen = new Set;
|
|
3705
|
+
let c;
|
|
3706
|
+
while (ctx.p < ctx.s.length) {
|
|
3707
|
+
skipVoid(ctx);
|
|
3708
|
+
if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
|
|
3709
|
+
ctx.p++;
|
|
3710
|
+
return res;
|
|
3711
|
+
}
|
|
3712
|
+
let k;
|
|
3713
|
+
let t2 = res;
|
|
3714
|
+
let hasOwn = false;
|
|
3715
|
+
let errPtr = ctx.p;
|
|
3716
|
+
let key = parseKey(ctx);
|
|
3717
|
+
for (let i2 = 0;i2 < key.length; i2++) {
|
|
3718
|
+
if (i2)
|
|
3719
|
+
t2 = hasOwn ? t2[k] : t2[k] = Object.create(null);
|
|
3720
|
+
k = key[i2];
|
|
3721
|
+
if ((hasOwn = Object.hasOwn(t2, k)) && (typeof t2[k] !== "object" || seen.has(t2[k]))) {
|
|
3722
|
+
TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
3723
|
+
}
|
|
3724
|
+
let unsafe = k === "__proto__";
|
|
3725
|
+
if (ctx.uk && (unsafe || k === "constructor")) {
|
|
3726
|
+
t2 = ctx.uk !== 1 && TomlError.x("document contains an unsafe property", ctx, errPtr);
|
|
3727
|
+
break;
|
|
3728
|
+
}
|
|
3729
|
+
if (!hasOwn && unsafe) {
|
|
3730
|
+
Object.defineProperty(t2, k, { enumerable: true, configurable: true, writable: true });
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3733
|
+
if (hasOwn) {
|
|
3734
|
+
TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
3735
|
+
}
|
|
3736
|
+
skipVoid(ctx, true, true);
|
|
3737
|
+
let value = extractValue(ctx, 125);
|
|
3738
|
+
if (t2 && typeof (t2[k] = value) === "object")
|
|
3739
|
+
seen.add(value);
|
|
3740
|
+
skipVoid(ctx);
|
|
3741
|
+
if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) {
|
|
3742
|
+
return res;
|
|
3743
|
+
}
|
|
3744
|
+
if (c !== 44)
|
|
3745
|
+
TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
3746
|
+
}
|
|
3747
|
+
TomlError.x("unfinished table", ctx, startPtr);
|
|
3748
|
+
}
|
|
3749
|
+
function parseArray(ctx) {
|
|
3750
|
+
let startPtr = ctx.p++;
|
|
3751
|
+
let res = [];
|
|
3752
|
+
let c;
|
|
3753
|
+
while (ctx.p < ctx.s.length) {
|
|
3754
|
+
skipVoid(ctx);
|
|
3755
|
+
if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
|
|
3756
|
+
ctx.p++;
|
|
3757
|
+
return res;
|
|
3758
|
+
}
|
|
3759
|
+
res.push(extractValue(ctx, 93));
|
|
3760
|
+
skipVoid(ctx);
|
|
3761
|
+
if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) {
|
|
3762
|
+
return res;
|
|
3763
|
+
}
|
|
3764
|
+
if (c !== 44)
|
|
3765
|
+
TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
3766
|
+
}
|
|
3767
|
+
TomlError.x("unfinished array", ctx, startPtr);
|
|
3768
|
+
}
|
|
3769
|
+
|
|
3770
|
+
// server/node_modules/smol-toml/dist/parse.js
|
|
3771
|
+
/*!
|
|
3772
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3773
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
3774
|
+
*
|
|
3775
|
+
* Redistribution and use in source and binary forms, with or without
|
|
3776
|
+
* modification, are permitted provided that the following conditions are met:
|
|
3777
|
+
*
|
|
3778
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
3779
|
+
* list of conditions and the following disclaimer.
|
|
3780
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
3781
|
+
* this list of conditions and the following disclaimer in the
|
|
3782
|
+
* documentation and/or other materials provided with the distribution.
|
|
3783
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
3784
|
+
* may be used to endorse or promote products derived from this software without
|
|
3785
|
+
* specific prior written permission.
|
|
3786
|
+
*
|
|
3787
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
3788
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
3789
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
3790
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
3791
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
3792
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
3793
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
3794
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
3795
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
3796
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3797
|
+
*/
|
|
3798
|
+
function peekTable(ctx, key, table, meta, type) {
|
|
3799
|
+
let t2 = table;
|
|
3800
|
+
let m = meta;
|
|
3801
|
+
let k;
|
|
3802
|
+
let hasOwn = false;
|
|
3803
|
+
let state;
|
|
3804
|
+
for (let i2 = 0;i2 < key.length; i2++) {
|
|
3805
|
+
if (i2) {
|
|
3806
|
+
t2 = hasOwn ? t2[k] : t2[k] = Object.create(null);
|
|
3807
|
+
m = (state = m[k]).c;
|
|
3808
|
+
if (type === 0 && (state.t === 1 || state.t === 2)) {
|
|
3809
|
+
return null;
|
|
3810
|
+
}
|
|
3811
|
+
if (state.t === 2) {
|
|
3812
|
+
let l = t2.length - 1;
|
|
3813
|
+
t2 = t2[l];
|
|
3814
|
+
m = m[l].c;
|
|
3815
|
+
}
|
|
3816
|
+
}
|
|
3817
|
+
k = key[i2];
|
|
3818
|
+
if ((hasOwn = Object.hasOwn(t2, k)) && m[k]?.t === 0 && m[k]?.d) {
|
|
3819
|
+
return null;
|
|
3820
|
+
}
|
|
3821
|
+
if (!hasOwn) {
|
|
3822
|
+
let unsafe = k === "__proto__";
|
|
3823
|
+
if (ctx.uk && (unsafe || k === "constructor"))
|
|
3824
|
+
return false;
|
|
3825
|
+
if (unsafe) {
|
|
3826
|
+
Object.defineProperty(t2, k, { enumerable: true, configurable: true, writable: true });
|
|
3827
|
+
Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
|
|
3828
|
+
}
|
|
3829
|
+
m[k] = {
|
|
3830
|
+
t: i2 < key.length - 1 && type === 2 ? 3 : type,
|
|
3831
|
+
d: false,
|
|
3832
|
+
i: 0,
|
|
3833
|
+
c: Object.create(null)
|
|
3834
|
+
};
|
|
3835
|
+
}
|
|
3836
|
+
}
|
|
3837
|
+
state = m[k];
|
|
3838
|
+
if (state.t !== type && !(type === 1 && state.t === 3)) {
|
|
3839
|
+
return null;
|
|
3840
|
+
}
|
|
3841
|
+
if (type === 2) {
|
|
3842
|
+
if (!state.d) {
|
|
3843
|
+
state.d = true;
|
|
3844
|
+
t2[k] = [];
|
|
3845
|
+
}
|
|
3846
|
+
t2[k].push(t2 = Object.create(null));
|
|
3847
|
+
state.c[state.i++] = state = { t: 1, d: false, i: 0, c: Object.create(null) };
|
|
3848
|
+
}
|
|
3849
|
+
if (state.d) {
|
|
3850
|
+
return null;
|
|
3851
|
+
}
|
|
3852
|
+
state.d = true;
|
|
3853
|
+
if (type === 1) {
|
|
3854
|
+
t2 = hasOwn ? t2[k] : t2[k] = Object.create(null);
|
|
3855
|
+
} else if (type === 0 && hasOwn) {
|
|
3856
|
+
return null;
|
|
3857
|
+
}
|
|
3858
|
+
return [k, t2, state.c];
|
|
3859
|
+
}
|
|
3860
|
+
function validateTablePeek(ctx, peek, ptr) {
|
|
3861
|
+
if (peek === null || ctx.uk === 2)
|
|
3862
|
+
TomlError.x(peek === null ? "trying to redefine an already defined table or value" : "document contains an unsafe property", ctx, ptr);
|
|
3863
|
+
}
|
|
3864
|
+
function parse(toml, options = {}) {
|
|
3865
|
+
let ctx = {
|
|
3866
|
+
s: toml,
|
|
3867
|
+
p: 0,
|
|
3868
|
+
d: options.maxDepth ?? 1000,
|
|
3869
|
+
bi: options.integersAsBigInt ?? false,
|
|
3870
|
+
ld: options.useLegacyDate ?? true,
|
|
3871
|
+
uk: options.unsafeKeyBehaviour === "throw" ? 2 : options.unsafeKeyBehaviour === "drop" ? 1 : 0
|
|
3872
|
+
};
|
|
3873
|
+
let res = Object.create(null);
|
|
3874
|
+
let meta = Object.create(null);
|
|
3875
|
+
let tmp;
|
|
3876
|
+
let skipping = false;
|
|
3877
|
+
let tbl = res;
|
|
3878
|
+
let m = meta;
|
|
3879
|
+
if (toml.charCodeAt(0) === 65279)
|
|
3880
|
+
ctx.p++;
|
|
3881
|
+
skipVoid(ctx);
|
|
3882
|
+
while (ctx.p < toml.length) {
|
|
3883
|
+
if (toml.charCodeAt(ctx.p) === 91) {
|
|
3884
|
+
let isTableArray = toml.charCodeAt(++ctx.p) === 91;
|
|
3885
|
+
tmp = ctx.p += +isTableArray;
|
|
3886
|
+
skipping = false;
|
|
3887
|
+
let k = parseKey(ctx, 93);
|
|
3888
|
+
if (isTableArray) {
|
|
3889
|
+
if (toml.charCodeAt(ctx.p) !== 93) {
|
|
3890
|
+
TomlError.x("expected end of table array declaration", ctx);
|
|
3891
|
+
}
|
|
3892
|
+
ctx.p++;
|
|
3893
|
+
}
|
|
3894
|
+
let p = peekTable(ctx, k, res, meta, isTableArray ? 2 : 1);
|
|
3895
|
+
if (!p) {
|
|
3896
|
+
validateTablePeek(ctx, p, tmp);
|
|
3897
|
+
skipping = true;
|
|
3898
|
+
} else {
|
|
3899
|
+
m = p[2];
|
|
3900
|
+
tbl = p[1];
|
|
3901
|
+
}
|
|
3902
|
+
} else {
|
|
3903
|
+
tmp = ctx.p;
|
|
3904
|
+
let k = parseKey(ctx);
|
|
3905
|
+
let p = peekTable(ctx, k, tbl, m, 0);
|
|
3906
|
+
if (!p && !skipping)
|
|
3907
|
+
validateTablePeek(ctx, p, tmp);
|
|
3908
|
+
skipVoid(ctx, true, true);
|
|
3909
|
+
let v = extractValue(ctx, undefined);
|
|
3910
|
+
if (p && !skipping)
|
|
3911
|
+
p[1][p[0]] = v;
|
|
3912
|
+
}
|
|
3913
|
+
skipVoid(ctx, true);
|
|
3914
|
+
if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && (tmp !== 13 || toml.charCodeAt(ctx.p + 1) !== 10)) {
|
|
3915
|
+
TomlError.x("each key-value declaration must be followed by an end-of-line", ctx);
|
|
3916
|
+
}
|
|
3917
|
+
skipVoid(ctx);
|
|
3918
|
+
}
|
|
3919
|
+
return res;
|
|
3920
|
+
}
|
|
3921
|
+
|
|
3922
|
+
// server/node_modules/smol-toml/dist/stringify.js
|
|
3923
|
+
/*!
|
|
3924
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3925
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
3926
|
+
*
|
|
3927
|
+
* Redistribution and use in source and binary forms, with or without
|
|
3928
|
+
* modification, are permitted provided that the following conditions are met:
|
|
3929
|
+
*
|
|
3930
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
3931
|
+
* list of conditions and the following disclaimer.
|
|
3932
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
3933
|
+
* this list of conditions and the following disclaimer in the
|
|
3934
|
+
* documentation and/or other materials provided with the distribution.
|
|
3935
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
3936
|
+
* may be used to endorse or promote products derived from this software without
|
|
3937
|
+
* specific prior written permission.
|
|
3938
|
+
*
|
|
3939
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
3940
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
3941
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
3942
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
3943
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
3944
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
3945
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
3946
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
3947
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
3948
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3949
|
+
*/
|
|
3950
|
+
var HAS_WELLFORMED = !!"".isWellFormed;
|
|
3951
|
+
|
|
3952
|
+
// server/node_modules/smol-toml/dist/index.js
|
|
3953
|
+
/*!
|
|
3954
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3955
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
3956
|
+
*
|
|
3957
|
+
* Redistribution and use in source and binary forms, with or without
|
|
3958
|
+
* modification, are permitted provided that the following conditions are met:
|
|
3959
|
+
*
|
|
3960
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
3961
|
+
* list of conditions and the following disclaimer.
|
|
3962
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
3963
|
+
* this list of conditions and the following disclaimer in the
|
|
3964
|
+
* documentation and/or other materials provided with the distribution.
|
|
3965
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
3966
|
+
* may be used to endorse or promote products derived from this software without
|
|
3967
|
+
* specific prior written permission.
|
|
3968
|
+
*
|
|
3969
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
3970
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
3971
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
3972
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
3973
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
3974
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
3975
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
3976
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
3977
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
3978
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3979
|
+
*/
|
|
3980
|
+
|
|
3981
|
+
// server/src/codex-trust.ts
|
|
3982
|
+
var CODEX_TRUST_VERIFIED = ["0.160.0"];
|
|
3983
|
+
var LABELS = {
|
|
3984
|
+
PreToolUse: "pre_tool_use",
|
|
3985
|
+
PermissionRequest: "permission_request",
|
|
3986
|
+
PostToolUse: "post_tool_use",
|
|
3987
|
+
PreCompact: "pre_compact",
|
|
3988
|
+
PostCompact: "post_compact",
|
|
3989
|
+
SessionStart: "session_start",
|
|
3990
|
+
SessionEnd: "session_end",
|
|
3991
|
+
UserPromptSubmit: "user_prompt_submit",
|
|
3992
|
+
SubagentStart: "subagent_start",
|
|
3993
|
+
SubagentStop: "subagent_stop",
|
|
3994
|
+
Stop: "stop",
|
|
3995
|
+
Interrupt: "interrupt"
|
|
3996
|
+
};
|
|
3997
|
+
var NO_MATCHER = new Set(["UserPromptSubmit", "Stop", "Interrupt"]);
|
|
3998
|
+
var CONTEXT = new Set(["PreToolUse", "PostToolUse", "SessionStart", "UserPromptSubmit", "SubagentStart"]);
|
|
3999
|
+
var DEFAULT_CONTEXT_LIMIT = 2500;
|
|
4000
|
+
var SHORT = new Set(["SessionEnd", "Interrupt"]);
|
|
4001
|
+
var RUST_SPACE = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]+|[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]+$/g;
|
|
4002
|
+
var isTable = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4003
|
+
var isCount = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
|
|
4004
|
+
function canonical(v) {
|
|
4005
|
+
if (Array.isArray(v))
|
|
4006
|
+
return `[${v.map(canonical).join(",")}]`;
|
|
4007
|
+
if (isTable(v))
|
|
4008
|
+
return `{${Object.keys(v).sort().map((k) => `${JSON.stringify(k)}:${canonical(v[k])}`).join(",")}}`;
|
|
4009
|
+
return JSON.stringify(v);
|
|
4010
|
+
}
|
|
4011
|
+
var sha256 = (text) => `sha256:${crypto.createHash("sha256").update(text).digest("hex")}`;
|
|
4012
|
+
function readHookStates(configToml) {
|
|
4013
|
+
const states = new Map;
|
|
4014
|
+
if (configToml === null)
|
|
4015
|
+
return states;
|
|
4016
|
+
let config;
|
|
4017
|
+
try {
|
|
4018
|
+
config = parse(configToml);
|
|
4019
|
+
} catch {
|
|
4020
|
+
return { unknown: "config.toml could not be parsed" };
|
|
4021
|
+
}
|
|
4022
|
+
const hooks = isTable(config) ? config.hooks : undefined;
|
|
4023
|
+
if (hooks === undefined)
|
|
4024
|
+
return states;
|
|
4025
|
+
const table = isTable(hooks) ? hooks.state : undefined;
|
|
4026
|
+
if (table === undefined)
|
|
4027
|
+
return states;
|
|
4028
|
+
if (!isTable(table))
|
|
4029
|
+
return { unknown: "hooks.state in config.toml is not a table" };
|
|
4030
|
+
for (const [raw, value] of Object.entries(table)) {
|
|
4031
|
+
const key = raw.replace(RUST_SPACE, "");
|
|
4032
|
+
if (!key || !isTable(value))
|
|
4033
|
+
continue;
|
|
4034
|
+
const { enabled, trusted_hash } = value;
|
|
4035
|
+
if (enabled !== undefined && typeof enabled !== "boolean" || trusted_hash !== undefined && typeof trusted_hash !== "string")
|
|
4036
|
+
continue;
|
|
4037
|
+
const s = states.get(key) ?? {};
|
|
4038
|
+
if (enabled !== undefined)
|
|
4039
|
+
s.enabled = enabled;
|
|
4040
|
+
if (trusted_hash !== undefined)
|
|
4041
|
+
s.trusted_hash = trusted_hash;
|
|
4042
|
+
states.set(key, s);
|
|
4043
|
+
}
|
|
4044
|
+
return states;
|
|
4045
|
+
}
|
|
4046
|
+
function hookTrust(hooksJson, pluginId, relativePath, platform, states) {
|
|
4047
|
+
let file;
|
|
4048
|
+
try {
|
|
4049
|
+
file = JSON.parse(hooksJson, (_key, value, context) => typeof value === "number" && /[.eE]/.test(context?.source ?? "") ? Number.NaN : value);
|
|
4050
|
+
} catch {
|
|
4051
|
+
return { unknown: "the hooks file is not JSON" };
|
|
4052
|
+
}
|
|
4053
|
+
if (isTable(file) && (Object.keys(file).some((k) => k !== "hooks" && k !== "description") || file.description != null && typeof file.description !== "string"))
|
|
4054
|
+
return { unknown: "the hooks file has a top-level field Codex would not read" };
|
|
4055
|
+
const events = isTable(file) ? file.hooks : undefined;
|
|
4056
|
+
if (!isTable(events))
|
|
4057
|
+
return { unknown: "the hooks file has no hooks table" };
|
|
4058
|
+
const hooks = [];
|
|
4059
|
+
for (const [event, groups] of Object.entries(events)) {
|
|
4060
|
+
const label = LABELS[event];
|
|
4061
|
+
if (!label)
|
|
4062
|
+
return { unknown: `the hooks file has an event Codex does not know (${event})` };
|
|
4063
|
+
if (!Array.isArray(groups))
|
|
4064
|
+
return { unknown: `${event} in the hooks file is not a list` };
|
|
4065
|
+
for (const [g, group2] of groups.entries()) {
|
|
4066
|
+
if (!isTable(group2) || !Array.isArray(group2.hooks))
|
|
4067
|
+
return { unknown: `a ${event} group has no hooks list` };
|
|
4068
|
+
if (group2.matcher !== undefined && group2.matcher !== null && typeof group2.matcher !== "string")
|
|
4069
|
+
return { unknown: `a ${event} matcher is not a string` };
|
|
4070
|
+
const matcher = NO_MATCHER.has(event) ? undefined : group2.matcher ?? undefined;
|
|
4071
|
+
for (const [h2, handler] of group2.hooks.entries()) {
|
|
4072
|
+
if (!isTable(handler) || handler.type !== "command")
|
|
4073
|
+
return { unknown: `a ${event} hook is not a command` };
|
|
4074
|
+
const { command, timeout, statusMessage, additionalContextLimit } = handler;
|
|
4075
|
+
if ("commandWindows" in handler && "command_windows" in handler)
|
|
4076
|
+
return { unknown: `a ${event} hook names its Windows command twice` };
|
|
4077
|
+
const commandWindows = handler.commandWindows ?? handler.command_windows;
|
|
4078
|
+
if (typeof command !== "string" || commandWindows !== undefined && commandWindows !== null && typeof commandWindows !== "string" || timeout !== undefined && timeout !== null && !isCount(timeout) || handler.async !== undefined && typeof handler.async !== "boolean" || statusMessage !== undefined && statusMessage !== null && typeof statusMessage !== "string" || additionalContextLimit !== undefined && additionalContextLimit !== null && !isCount(additionalContextLimit))
|
|
4079
|
+
return { unknown: `a ${event} hook has a field Codex would not read` };
|
|
4080
|
+
const chosen = platform === "win32" ? commandWindows ?? command : command;
|
|
4081
|
+
if (!chosen.trim())
|
|
4082
|
+
return { unknown: `a ${event} hook has an empty command` };
|
|
4083
|
+
const given = timeout ?? undefined;
|
|
4084
|
+
const seconds = SHORT.has(event) ? Math.min(Math.max(given ?? 1, 1), 3) : Math.max(given ?? 600, 1);
|
|
4085
|
+
const limit = CONTEXT.has(event) && additionalContextLimit != null && additionalContextLimit !== DEFAULT_CONTEXT_LIMIT ? additionalContextLimit : undefined;
|
|
4086
|
+
const normalized = {
|
|
4087
|
+
type: "command",
|
|
4088
|
+
command: chosen,
|
|
4089
|
+
timeout: seconds,
|
|
4090
|
+
async: handler.async === true
|
|
4091
|
+
};
|
|
4092
|
+
if (typeof statusMessage === "string")
|
|
4093
|
+
normalized.statusMessage = statusMessage;
|
|
4094
|
+
if (limit !== undefined)
|
|
4095
|
+
normalized.additionalContextLimit = limit;
|
|
4096
|
+
const identity = { event_name: label, hooks: [normalized] };
|
|
4097
|
+
if (typeof matcher === "string")
|
|
4098
|
+
identity.matcher = matcher;
|
|
4099
|
+
const hash = sha256(canonical(identity));
|
|
4100
|
+
const key = `${pluginId}:${relativePath}:${label}:${g}:${h2}`;
|
|
4101
|
+
const state = states.get(key);
|
|
4102
|
+
const stored = state?.trusted_hash;
|
|
4103
|
+
const trust = stored === undefined ? "untrusted" : stored === hash ? "trusted" : "modified";
|
|
4104
|
+
hooks.push({ key, hash, trust, enabled: state?.enabled !== false });
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
}
|
|
4108
|
+
if (!hooks.length)
|
|
4109
|
+
return { unknown: "the hooks file defines no hooks" };
|
|
4110
|
+
return { hooks };
|
|
4111
|
+
}
|
|
4112
|
+
|
|
3010
4113
|
// server/src/panel.ts
|
|
3011
4114
|
import { stripVTControlCharacters as stripVTControlCharacters2, styleText as styleText2 } from "node:util";
|
|
3012
4115
|
|
|
3013
4116
|
// server/src/text.ts
|
|
3014
|
-
import
|
|
4117
|
+
import crypto2 from "node:crypto";
|
|
3015
4118
|
var segmenter = new Intl.Segmenter("ja", { granularity: "word" });
|
|
3016
4119
|
var HIRAGANA_ONLY = /^[\p{Script=Hiragana}ー]+$/u;
|
|
3017
4120
|
var STOP = new Set(["the", "a", "an", "of", "to", "in", "is", "and", "or", "for", "on", "it", "be"]);
|
|
@@ -3109,9 +4212,9 @@ var QUESTION = new Set([
|
|
|
3109
4212
|
...["理由", "仕組", "何", "方", "場合", "今", "件"]
|
|
3110
4213
|
]);
|
|
3111
4214
|
var FOLDED_QUESTION = new Set([...QUESTION].flatMap((w) => terms(w)));
|
|
3112
|
-
var
|
|
4215
|
+
var sha2562 = (s) => crypto2.createHash("sha256").update(s).digest();
|
|
3113
4216
|
function uuidFrom(...parts) {
|
|
3114
|
-
const b =
|
|
4217
|
+
const b = crypto2.createHash("sha256").update(parts.join("\x00")).digest().subarray(0, 16);
|
|
3115
4218
|
b[6] = (b[6] ?? 0) & 15 | 128;
|
|
3116
4219
|
b[8] = (b[8] ?? 0) & 63 | 128;
|
|
3117
4220
|
const h2 = b.toString("hex");
|
|
@@ -3469,11 +4572,18 @@ function observe(cwdRoot, platform = process.platform, env = process.env, execPa
|
|
|
3469
4572
|
} catch {}
|
|
3470
4573
|
const codexCache = path2.join(codexHome, "plugins", "cache");
|
|
3471
4574
|
const codex = [];
|
|
4575
|
+
const markets = [];
|
|
3472
4576
|
for (const market of safeDirs(codexCache)) {
|
|
3473
4577
|
for (const v of safeDirs(path2.join(codexCache, market, "sphica"))) {
|
|
3474
4578
|
codex.push(install(path2.join(codexCache, market, "sphica", v)));
|
|
4579
|
+
markets.push(market);
|
|
3475
4580
|
}
|
|
3476
4581
|
}
|
|
4582
|
+
let codexHooks;
|
|
4583
|
+
if (codex.length > 1)
|
|
4584
|
+
codexHooks = { unknown: "more than one Codex cache" };
|
|
4585
|
+
else if (codex[0] && markets[0])
|
|
4586
|
+
codexHooks = codexHookTrust(codex[0].root, `sphica@${markets[0]}`, codexHome, platform, env, execPath);
|
|
3477
4587
|
let running;
|
|
3478
4588
|
if (platform === "win32")
|
|
3479
4589
|
running = { unknown: "not checked on Windows" };
|
|
@@ -3527,7 +4637,88 @@ function observe(cwdRoot, platform = process.platform, env = process.env, execPa
|
|
|
3527
4637
|
} catch {
|
|
3528
4638
|
global = { unknown: "npm root -g failed" };
|
|
3529
4639
|
}
|
|
3530
|
-
return {
|
|
4640
|
+
return {
|
|
4641
|
+
repository,
|
|
4642
|
+
cli: install(ROOT),
|
|
4643
|
+
global,
|
|
4644
|
+
claude,
|
|
4645
|
+
claudeVersion,
|
|
4646
|
+
codex,
|
|
4647
|
+
codexCache,
|
|
4648
|
+
codexHooks,
|
|
4649
|
+
running
|
|
4650
|
+
};
|
|
4651
|
+
}
|
|
4652
|
+
function codexCommand(platform, env, execPath) {
|
|
4653
|
+
if (platform !== "win32")
|
|
4654
|
+
return ["codex", ["--version"]];
|
|
4655
|
+
const exts = (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
|
|
4656
|
+
for (const dir of (env.PATH ?? env.Path ?? "").split(";").filter(Boolean))
|
|
4657
|
+
for (const ext of exts) {
|
|
4658
|
+
const at = path2.join(dir, `codex${ext.toLowerCase()}`);
|
|
4659
|
+
if (!fs2.existsSync(at))
|
|
4660
|
+
continue;
|
|
4661
|
+
if (ext.toLowerCase() === ".exe")
|
|
4662
|
+
return [at, ["--version"]];
|
|
4663
|
+
const js = path2.join(dir, "node_modules", "@openai", "codex", "bin", "codex.js");
|
|
4664
|
+
return fs2.existsSync(js) ? [execPath, [js, "--version"]] : null;
|
|
4665
|
+
}
|
|
4666
|
+
return null;
|
|
4667
|
+
}
|
|
4668
|
+
function codexHookTrust(root, pluginId, codexHome, platform, env, execPath) {
|
|
4669
|
+
const command = codexCommand(platform, env, execPath);
|
|
4670
|
+
if (!command)
|
|
4671
|
+
return { unknown: "no codex.exe, or codex.js beside codex.cmd, on PATH" };
|
|
4672
|
+
let version2;
|
|
4673
|
+
try {
|
|
4674
|
+
const out = execFileSync(command[0], command[1], {
|
|
4675
|
+
encoding: "utf8",
|
|
4676
|
+
env,
|
|
4677
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
4678
|
+
timeout: 1e4
|
|
4679
|
+
});
|
|
4680
|
+
version2 = /^codex-cli (\d+\.\d+\.\d+)$/m.exec(out)?.[1];
|
|
4681
|
+
} catch {
|
|
4682
|
+
return { unknown: "codex --version failed" };
|
|
4683
|
+
}
|
|
4684
|
+
if (!version2)
|
|
4685
|
+
return { unknown: "codex --version printed no version" };
|
|
4686
|
+
if (!CODEX_TRUST_VERIFIED.includes(version2))
|
|
4687
|
+
return {
|
|
4688
|
+
unknown: `Codex ${version2}; Sphica reads its hook trust only for ${CODEX_TRUST_VERIFIED.join(", ")}`
|
|
4689
|
+
};
|
|
4690
|
+
let file;
|
|
4691
|
+
try {
|
|
4692
|
+
const manifest = JSON.parse(fs2.readFileSync(path2.join(root, ".codex-plugin", "plugin.json"), "utf8"));
|
|
4693
|
+
if (typeof manifest.hooks !== "string")
|
|
4694
|
+
return { unknown: "the Codex plugin manifest names no hooks file" };
|
|
4695
|
+
file = path2.resolve(root, manifest.hooks);
|
|
4696
|
+
} catch {
|
|
4697
|
+
return { unknown: "the Codex plugin manifest could not be read" };
|
|
4698
|
+
}
|
|
4699
|
+
const relative = path2.relative(root, file);
|
|
4700
|
+
if (!relative || relative.startsWith("..") || path2.isAbsolute(relative))
|
|
4701
|
+
return { unknown: "the hooks file is outside the plugin" };
|
|
4702
|
+
let hooksJson;
|
|
4703
|
+
try {
|
|
4704
|
+
hooksJson = fs2.readFileSync(file, "utf8");
|
|
4705
|
+
} catch {
|
|
4706
|
+
return { unknown: "the hooks file could not be read" };
|
|
4707
|
+
}
|
|
4708
|
+
const config = path2.join(codexHome, "config.toml");
|
|
4709
|
+
let toml;
|
|
4710
|
+
try {
|
|
4711
|
+
toml = fs2.readFileSync(config, "utf8");
|
|
4712
|
+
} catch (e) {
|
|
4713
|
+
if (e.code !== "ENOENT")
|
|
4714
|
+
return { unknown: "config.toml could not be read" };
|
|
4715
|
+
toml = null;
|
|
4716
|
+
}
|
|
4717
|
+
const states = readHookStates(toml);
|
|
4718
|
+
if (!(states instanceof Map))
|
|
4719
|
+
return states;
|
|
4720
|
+
const trust = hookTrust(hooksJson, pluginId, relative.split(path2.sep).join("/"), platform, states);
|
|
4721
|
+
return "unknown" in trust ? trust : { config, hooks: trust.hooks };
|
|
3531
4722
|
}
|
|
3532
4723
|
function safeDirs(dir) {
|
|
3533
4724
|
try {
|
|
@@ -3651,6 +4842,29 @@ ${indent}${caution(note)}` : ""}`);
|
|
|
3651
4842
|
todo.add("codex");
|
|
3652
4843
|
row("Codex", x2, note);
|
|
3653
4844
|
}
|
|
4845
|
+
if (unknown(s.codexHooks))
|
|
4846
|
+
say("none", "Codex hooks", `unknown (${s.codexHooks.unknown}). Check /hooks in Codex`);
|
|
4847
|
+
else if (s.codexHooks) {
|
|
4848
|
+
const { hooks, config } = s.codexHooks;
|
|
4849
|
+
const count = (t2) => hooks.filter((h2) => h2.trust === t2).length;
|
|
4850
|
+
const trusted = count("trusted");
|
|
4851
|
+
const disabled = hooks.filter((h2) => !h2.enabled).length;
|
|
4852
|
+
const summary = `${trusted} of ${hooks.length} trusted in ${short(config)}`;
|
|
4853
|
+
if (trusted === hooks.length && !disabled)
|
|
4854
|
+
say("ok", "Codex hooks", summary);
|
|
4855
|
+
else {
|
|
4856
|
+
const parts = [
|
|
4857
|
+
[count("modified"), "modified"],
|
|
4858
|
+
[count("untrusted"), "untrusted"],
|
|
4859
|
+
[disabled, "disabled"]
|
|
4860
|
+
].filter(([n2]) => n2);
|
|
4861
|
+
const steps = [
|
|
4862
|
+
trusted < hooks.length ? "open /hooks in Codex and trust Sphica's hooks" : "",
|
|
4863
|
+
disabled ? "enable the disabled ones in /hooks if that was not intended" : ""
|
|
4864
|
+
].filter(Boolean);
|
|
4865
|
+
say("warn", "Codex hooks", `${summary}; ${parts.map(([n2, w]) => `${n2} ${w}`).join(", ")}. ${steps.join("; ")}`);
|
|
4866
|
+
}
|
|
4867
|
+
}
|
|
3654
4868
|
const x = s.codex.length === 1 ? s.codex[0] : undefined;
|
|
3655
4869
|
if (!base && s.claude && !unknown(s.claude) && x && s.claude.version === x.version) {
|
|
3656
4870
|
if (fs2.existsSync(s.claude.root) && differingFiles(s.claude.root, x.root).length) {
|
|
@@ -14511,36 +15725,36 @@ class ParseJSONResultsPlugin {
|
|
|
14511
15725
|
async transformResult(args) {
|
|
14512
15726
|
return {
|
|
14513
15727
|
...args.result,
|
|
14514
|
-
rows:
|
|
15728
|
+
rows: parseArray2(args.result.rows, "$", this.#options)
|
|
14515
15729
|
};
|
|
14516
15730
|
}
|
|
14517
15731
|
}
|
|
14518
|
-
function
|
|
15732
|
+
function parseArray2(arr, jsonPath, options) {
|
|
14519
15733
|
const target = options.objectStrategy === "create" ? new Array(arr.length) : arr;
|
|
14520
15734
|
for (let i2 = 0;i2 < arr.length; ++i2) {
|
|
14521
|
-
target[i2] =
|
|
15735
|
+
target[i2] = parse2(arr[i2], `${jsonPath}[${i2}]`, options);
|
|
14522
15736
|
}
|
|
14523
15737
|
return target;
|
|
14524
15738
|
}
|
|
14525
|
-
function
|
|
15739
|
+
function parse2(value, jsonPath, options) {
|
|
14526
15740
|
if (isString(value)) {
|
|
14527
|
-
return
|
|
15741
|
+
return parseString2(value, jsonPath, options);
|
|
14528
15742
|
}
|
|
14529
15743
|
if (Array.isArray(value)) {
|
|
14530
|
-
return
|
|
15744
|
+
return parseArray2(value, jsonPath, options);
|
|
14531
15745
|
}
|
|
14532
15746
|
if (isPlainObject(value)) {
|
|
14533
15747
|
return parseObject(value, jsonPath, options);
|
|
14534
15748
|
}
|
|
14535
15749
|
return value;
|
|
14536
15750
|
}
|
|
14537
|
-
function
|
|
15751
|
+
function parseString2(str, jsonPath, options) {
|
|
14538
15752
|
const { shouldParse } = options;
|
|
14539
15753
|
if (!shouldParse(str, jsonPath)) {
|
|
14540
15754
|
return str;
|
|
14541
15755
|
}
|
|
14542
15756
|
try {
|
|
14543
|
-
return
|
|
15757
|
+
return parse2(JSON.parse(str, (key, value, ...otherArgs) => {
|
|
14544
15758
|
if (key === "__proto__") {
|
|
14545
15759
|
return;
|
|
14546
15760
|
}
|
|
@@ -14567,7 +15781,7 @@ function parseObject(obj, jsonPath, options) {
|
|
|
14567
15781
|
if (key === "__proto__") {
|
|
14568
15782
|
continue;
|
|
14569
15783
|
}
|
|
14570
|
-
const parsed =
|
|
15784
|
+
const parsed = parse2(obj[key], `${jsonPath}."${key}"`, options);
|
|
14571
15785
|
if (key === "constructor" && isPlainObject(parsed) && Object.hasOwn(parsed, "prototype")) {
|
|
14572
15786
|
delete parsed.prototype;
|
|
14573
15787
|
}
|
|
@@ -15218,7 +16432,7 @@ var INJECTED = [
|
|
|
15218
16432
|
/^(?:\d+ background agents were stopped by the user:|Background agent ".*" was stopped by the user\.)/,
|
|
15219
16433
|
/^(?:Another Claude|A peer) session sent a message(?: while you were working)?:/
|
|
15220
16434
|
];
|
|
15221
|
-
var digest = (s) =>
|
|
16435
|
+
var digest = (s) => sha2562(s).toString("hex").slice(0, 16);
|
|
15222
16436
|
function answersOf(input) {
|
|
15223
16437
|
const response = input.tool_response;
|
|
15224
16438
|
const answers = response?.answers;
|
|
@@ -15575,7 +16789,7 @@ async function write(db, batch) {
|
|
|
15575
16789
|
truncated: x.m.truncated ? 1 : 0,
|
|
15576
16790
|
redacted: x.m.redacted ? 1 : 0,
|
|
15577
16791
|
original_bytes: x.m.originalBytes,
|
|
15578
|
-
content_hash:
|
|
16792
|
+
content_hash: sha2562(x.m.body)
|
|
15579
16793
|
}))).execute();
|
|
15580
16794
|
const after = await present();
|
|
15581
16795
|
const edits = batch.flatMap((r2) => {
|