kimi-plugin-cc 2.0.8 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +27 -0
- package/README.md +5 -5
- package/agents/kimi-ask.md +5 -1
- package/agents/kimi-challenge.md +4 -2
- package/agents/kimi-pursue.md +3 -1
- package/agents/kimi-rescue.md +5 -1
- package/agents/kimi-review.md +4 -2
- package/agents/kimi-swarm-write.md +3 -1
- package/agents/kimi-swarm.md +3 -1
- package/commands/ask.md +5 -3
- package/commands/challenge.md +5 -3
- package/commands/pursue.md +5 -1
- package/commands/rescue.md +5 -3
- package/commands/review.md +5 -3
- package/commands/swarm.md +5 -1
- package/dist/cli-client.js +42 -10
- package/dist/commands/ask.js +14 -7
- package/dist/commands/cli-helpers.js +66 -4
- package/dist/commands/pursue.js +7 -3
- package/dist/commands/rescue.js +16 -10
- package/dist/commands/result.js +5 -1
- package/dist/commands/review-gate.js +21 -14
- package/dist/commands/review.js +9 -5
- package/dist/commands/status.js +2 -2
- package/dist/commands/swarm.js +10 -4
- package/dist/help.js +1 -1
- package/dist/hook-escape.js +71 -0
- package/dist/hooks/approval-policy.js +17 -27
- package/dist/hooks/config-safety.js +15 -7
- package/dist/job-store.js +52 -7
- package/dist/kimi-engine.js +2 -0
- package/dist/kimi-errors.js +1 -1
- package/dist/kimi-timeouts.js +6 -10
- package/dist/kimi-version-probe.js +2 -2
- package/dist/parsing.js +59 -53
- package/dist/session-recovery.js +203 -0
- package/dist/vendor/smol-toml/date.js +50 -21
- package/dist/vendor/smol-toml/error.js +6 -2
- package/dist/vendor/smol-toml/extract.js +259 -66
- package/dist/vendor/smol-toml/parse.js +64 -48
- package/dist/vendor/smol-toml/primitive.js +107 -135
- package/dist/vendor/smol-toml/struct.js +106 -134
- package/dist/vendor/smol-toml/util.js +22 -78
- package/dist/version.js +1 -1
- package/docs/models.md +10 -0
- package/docs/registry-releases.md +24 -1
- package/docs/safety.md +59 -2
- package/package.json +1 -1
- package/plugins/kimi-codex/.codex-plugin/plugin.json +1 -1
- package/plugins/kimi-codex/dist/cli-client.js +42 -10
- package/plugins/kimi-codex/dist/commands/ask.js +14 -7
- package/plugins/kimi-codex/dist/commands/cli-helpers.js +66 -4
- package/plugins/kimi-codex/dist/commands/pursue.js +7 -3
- package/plugins/kimi-codex/dist/commands/rescue.js +16 -10
- package/plugins/kimi-codex/dist/commands/result.js +5 -1
- package/plugins/kimi-codex/dist/commands/review-gate.js +21 -14
- package/plugins/kimi-codex/dist/commands/review.js +9 -5
- package/plugins/kimi-codex/dist/commands/status.js +2 -2
- package/plugins/kimi-codex/dist/commands/swarm.js +10 -4
- package/plugins/kimi-codex/dist/help.js +1 -1
- package/plugins/kimi-codex/dist/hook-escape.js +71 -0
- package/plugins/kimi-codex/dist/hooks/approval-policy.js +17 -27
- package/plugins/kimi-codex/dist/hooks/config-safety.js +15 -7
- package/plugins/kimi-codex/dist/job-store.js +52 -7
- package/plugins/kimi-codex/dist/kimi-engine.js +2 -0
- package/plugins/kimi-codex/dist/kimi-errors.js +1 -1
- package/plugins/kimi-codex/dist/kimi-timeouts.js +6 -10
- package/plugins/kimi-codex/dist/kimi-version-probe.js +2 -2
- package/plugins/kimi-codex/dist/parsing.js +59 -53
- package/plugins/kimi-codex/dist/session-recovery.js +203 -0
- package/plugins/kimi-codex/dist/vendor/smol-toml/date.js +50 -21
- package/plugins/kimi-codex/dist/vendor/smol-toml/error.js +6 -2
- package/plugins/kimi-codex/dist/vendor/smol-toml/extract.js +259 -66
- package/plugins/kimi-codex/dist/vendor/smol-toml/parse.js +64 -48
- package/plugins/kimi-codex/dist/vendor/smol-toml/primitive.js +107 -135
- package/plugins/kimi-codex/dist/vendor/smol-toml/struct.js +106 -134
- package/plugins/kimi-codex/dist/vendor/smol-toml/util.js +22 -78
- package/plugins/kimi-codex/dist/version.js +1 -1
- package/plugins/kimi-codex/skills/kimi-ask/SKILL.md +4 -2
- package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +4 -2
- package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +3 -1
- package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +4 -2
- package/plugins/kimi-codex/skills/kimi-review/SKILL.md +4 -2
- package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +2 -0
- package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +3 -1
- package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +3 -1
|
@@ -25,76 +25,269 @@
|
|
|
25
25
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
26
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
27
|
*/
|
|
28
|
-
import { parseString
|
|
28
|
+
import { parseString } from './primitive.js';
|
|
29
29
|
import { parseArray, parseInlineTable } from './struct.js';
|
|
30
|
-
import { skipVoid, skipUntil, skipComment, getStringEnd } from './util.js';
|
|
31
30
|
import { TomlError } from './error.js';
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// (absence of control characters)
|
|
38
|
-
skipComment(str, commentIdx);
|
|
39
|
-
value = value.slice(0, commentIdx);
|
|
40
|
-
}
|
|
41
|
-
return [value.trimEnd(), commentIdx];
|
|
31
|
+
import { TomlDate } from './date.js';
|
|
32
|
+
function isDigit(char, base = 10) {
|
|
33
|
+
return base === 16
|
|
34
|
+
? (char > 0x2f && char < 0x3a) || (char > 0x40 && char < 0x47) || (char > 0x60 && char < 0x67)
|
|
35
|
+
: (char > 0x2f && char < 0x30 + base);
|
|
42
36
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
37
|
+
function isEndOfValue(char, delim) {
|
|
38
|
+
// Whitespace -- we're permissive on `\r` for performance; it'll be dealt with later anyway
|
|
39
|
+
return char === 0x20 || char === 0x9 /* \t */ || char === 0xa /* \n */ || char === 0xd /* \r */ ||
|
|
40
|
+
// Structure end or next value delimiter
|
|
41
|
+
(delim && (char === delim || char === 0x2c /* , */)) ||
|
|
42
|
+
// Comment
|
|
43
|
+
char === 0x23; /* # */
|
|
44
|
+
}
|
|
45
|
+
/** @internal */
|
|
46
|
+
export function extractValue(ctx, end) {
|
|
47
|
+
let errPtr = ctx.p;
|
|
48
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
49
|
+
// Structs
|
|
50
|
+
if (c === 0x5b /* [ */ || c === 0x7b /* { */) {
|
|
51
|
+
ctx.d-- || TomlError.x('document contains excessively nested structures. aborting.', ctx);
|
|
52
|
+
let value = c === 0x5b /* [ */
|
|
53
|
+
? parseArray(ctx)
|
|
54
|
+
: parseInlineTable(ctx);
|
|
55
|
+
ctx.d++;
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
// Strings
|
|
59
|
+
if (c === 0x22 /* " */ || c === 0x27 /* ' */) {
|
|
60
|
+
return parseString(ctx);
|
|
61
|
+
}
|
|
62
|
+
// Booleans
|
|
63
|
+
// We can fast-path because the first character is enough to know the only possible value
|
|
64
|
+
if (c === 0x74 /* t */) { // Only possible valid value is `true`
|
|
65
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 0x72 || ctx.s.charCodeAt(++ctx.p) !== 0x75 || ctx.s.charCodeAt(++ctx.p) !== 0x65)
|
|
66
|
+
TomlError.x('invalid value', ctx, errPtr);
|
|
67
|
+
return ctx.p++, true;
|
|
68
|
+
}
|
|
69
|
+
if (c === 0x66 /* f */) { // Only possible valid value is `false`
|
|
70
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 0x61 || ctx.s.charCodeAt(++ctx.p) !== 0x6c || ctx.s.charCodeAt(++ctx.p) !== 0x73 || ctx.s.charCodeAt(++ctx.p) !== 0x65)
|
|
71
|
+
TomlError.x('invalid value', ctx, errPtr);
|
|
72
|
+
return ctx.p++, false;
|
|
73
|
+
}
|
|
74
|
+
if (c === 0x2b /* + */ || c === 0x2d /* - */) {
|
|
75
|
+
return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 0x2c - c, end);
|
|
76
|
+
}
|
|
77
|
+
// Rough heuristic, but `parseDate` falls back to number parsing if it's a false positive.
|
|
78
|
+
// e.g.: `a = 1\n-------------- = 1` would match this heuristic, but gracefully fallback to numbers.
|
|
79
|
+
if (ctx.s.charCodeAt(ctx.p + 4) === 0x2d /* - */ && ctx.s.charCodeAt(ctx.p + 7) === 0x2d /* - */) {
|
|
80
|
+
return parseDate(ctx, c, end);
|
|
81
|
+
}
|
|
82
|
+
// Same logic as above; `parseTime` falls back to number parsing if it's a false positive.
|
|
83
|
+
if (ctx.s.charCodeAt(ctx.p + 2) === 0x3a /* : */) {
|
|
84
|
+
return parseTime(ctx, c, end);
|
|
85
|
+
}
|
|
86
|
+
return parseNumber(ctx, ctx.p, c, 0, end);
|
|
87
|
+
}
|
|
88
|
+
// State:
|
|
89
|
+
// 0: init
|
|
90
|
+
// 1: integer
|
|
91
|
+
// 2: fractional dot
|
|
92
|
+
// 3: fractional
|
|
93
|
+
// 4: exponent letter
|
|
94
|
+
// 5: exponent
|
|
95
|
+
// 6: exponent sign
|
|
96
|
+
// 7: exponent with sign
|
|
97
|
+
// >9: underscore; see below
|
|
98
|
+
// -> 12: was integer
|
|
99
|
+
// -> 14: was fractional
|
|
100
|
+
// -> 16: was exponent
|
|
101
|
+
// states 2-5, 14, 16 are ONLY permitted iif base === 10
|
|
102
|
+
function parseNumber(ctx, startPtr, startChr, sign, endChr) {
|
|
103
|
+
let c = startChr;
|
|
104
|
+
let state = 0;
|
|
105
|
+
let hasUnderscores = false;
|
|
106
|
+
// (+/-)inf
|
|
107
|
+
if (c === 0x69 /* i */) {
|
|
108
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 0x6e || ctx.s.charCodeAt(++ctx.p) !== 0x66)
|
|
109
|
+
TomlError.x('invalid value', ctx, startPtr);
|
|
110
|
+
return ctx.p++, (sign || 1) / 0;
|
|
111
|
+
}
|
|
112
|
+
// (+/-)nan
|
|
113
|
+
if (c === 0x6e /* n */) {
|
|
114
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 0x61 || ctx.s.charCodeAt(++ctx.p) !== 0x6e)
|
|
115
|
+
TomlError.x('invalid value', ctx, startPtr);
|
|
116
|
+
return ctx.p++, NaN;
|
|
117
|
+
}
|
|
118
|
+
// Leading zero
|
|
119
|
+
// Only allowed cases: `0<EOV>`, `0.(...)`, `0e(...)`, `0x(...)`, `0b(...)`, `0o(...)`
|
|
120
|
+
// FWIW, `0e(...)` is a stupid case, but it's not banned per-se so we have to parse it
|
|
121
|
+
if (c === 0x30 /* 0 */) {
|
|
122
|
+
if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr))
|
|
123
|
+
return ctx.bi === true ? 0n : 0; // note: conveniently deals with `-0`
|
|
124
|
+
if (!sign) {
|
|
125
|
+
if (c === 0x78 /* x */)
|
|
126
|
+
return parseIntegerBaseN(ctx, startPtr, 16, endChr);
|
|
127
|
+
else if (c === 0x62 /* b */)
|
|
128
|
+
return parseIntegerBaseN(ctx, startPtr, 2, endChr);
|
|
129
|
+
else if (c === 0x6f /* o */)
|
|
130
|
+
return parseIntegerBaseN(ctx, startPtr, 8, endChr);
|
|
131
|
+
}
|
|
132
|
+
if (c === 0x2e /* . */)
|
|
133
|
+
state = 2;
|
|
134
|
+
else if (c === 0x65 /* e */ || c === 0x45 /* E */)
|
|
135
|
+
state = 4;
|
|
136
|
+
else
|
|
137
|
+
TomlError.x('illegal leading zero', ctx, startPtr);
|
|
138
|
+
}
|
|
139
|
+
// If the 1st char is not a digit by now, then it's not a valid TOML value at all
|
|
140
|
+
else if (!isDigit(c))
|
|
141
|
+
TomlError.x('invalid value', ctx, startPtr);
|
|
142
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
143
|
+
if (!state)
|
|
144
|
+
state = 1; // Detects single-digit numbers we can use a fast parse path for
|
|
145
|
+
// The way the states are numbered is not random: underscores are always permitted in odd-numbered states and
|
|
146
|
+
// never permitted in even-numbered ones.
|
|
147
|
+
if (c === 0x5f /* _ */) {
|
|
148
|
+
if (!(state & 1))
|
|
149
|
+
TomlError.x('illegal underscore', ctx);
|
|
150
|
+
state += 11; // 11 is a marker that makes the state even and greater than 9; see the numbering + rationale above
|
|
151
|
+
hasUnderscores = true;
|
|
152
|
+
}
|
|
153
|
+
// Transition to fractional part.
|
|
154
|
+
else if (state === 1 && c === 0x2e /* . */)
|
|
155
|
+
state = 2;
|
|
156
|
+
// Transition to exponent part.
|
|
157
|
+
else if ((state === 1 || state === 3) && (c === 0x65 /* e */ || c === 0x45 /* E */))
|
|
158
|
+
state = 4;
|
|
159
|
+
// + and - are permitted in state 4 only (handled before entering the function for state 0)
|
|
160
|
+
else if (state === 4 && (c === 0x2b /* + */ || c === 0x2d /* - */)) {
|
|
161
|
+
state = 6;
|
|
162
|
+
}
|
|
163
|
+
// All special cases have been handled; only digits are allowed here
|
|
164
|
+
else if (!isDigit(c))
|
|
165
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
166
|
+
// Clear state flags
|
|
167
|
+
else if (state > 9)
|
|
168
|
+
state -= 11;
|
|
169
|
+
else if (!(state & 1))
|
|
170
|
+
state++;
|
|
171
|
+
}
|
|
172
|
+
// Single-char number; we can fast-path these very easily.
|
|
173
|
+
if (!state) {
|
|
174
|
+
let val = (startChr - 0x30 /* 0 */) * (sign || 1);
|
|
175
|
+
return ctx.bi === true ? BigInt(val) : val;
|
|
176
|
+
}
|
|
177
|
+
// Even-numbered states absolutely require a digit next; not even end of value is permitted
|
|
178
|
+
if (!(state & 1))
|
|
179
|
+
TomlError.x('unfinished numeric value', ctx, startPtr);
|
|
180
|
+
let str = ctx.s.slice(startPtr, ctx.p);
|
|
181
|
+
if (hasUnderscores)
|
|
182
|
+
str = str.replaceAll('_', ''); // perf: replaceAll 1.25x faster than replace with a regex
|
|
183
|
+
return state > 1
|
|
184
|
+
? parseFloat(str)
|
|
185
|
+
: parseInteger(ctx, str, 10, startPtr);
|
|
186
|
+
}
|
|
187
|
+
function parseIntegerBaseN(ctx, startPtr, base, endChr) {
|
|
188
|
+
let c, underscore = 1;
|
|
189
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
190
|
+
if (c === 0x5f /* _ */) {
|
|
191
|
+
if (underscore & 1)
|
|
192
|
+
TomlError.x('illegal underscore', ctx);
|
|
193
|
+
underscore = 3;
|
|
65
194
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
195
|
+
// We only need to check if the number is a valid digit, nothing else is permitted
|
|
196
|
+
else if (!isDigit(c, base))
|
|
197
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
198
|
+
// Clear underscore flag
|
|
199
|
+
else if (underscore & 1)
|
|
200
|
+
underscore--;
|
|
201
|
+
}
|
|
202
|
+
// Trailing underscore is not allowed
|
|
203
|
+
if (underscore & 1)
|
|
204
|
+
TomlError.x('unfinished numeric value', ctx);
|
|
205
|
+
let str = ctx.s.slice(startPtr + 2, ctx.p);
|
|
206
|
+
if (underscore)
|
|
207
|
+
str = str.replaceAll('_', ''); // perf: replaceAll 1.25x faster than replace with a regex
|
|
208
|
+
return parseInteger(ctx, str, base, startPtr);
|
|
209
|
+
}
|
|
210
|
+
function parseInteger(ctx, str, base, startPtr) {
|
|
211
|
+
if (ctx.bi !== true)
|
|
212
|
+
int: {
|
|
213
|
+
let val = parseInt(str, base);
|
|
214
|
+
if (!Number.isSafeInteger(val)) {
|
|
215
|
+
if (ctx.bi)
|
|
216
|
+
break int;
|
|
217
|
+
TomlError.x('integer value cannot be represented losslessly', ctx, startPtr);
|
|
79
218
|
}
|
|
80
|
-
|
|
219
|
+
return val;
|
|
220
|
+
}
|
|
221
|
+
return base === 10 ? BigInt(str) : BigInt((base === 2 ? '0b' : base === 8 ? '0o' : '0x') + str);
|
|
222
|
+
}
|
|
223
|
+
function parseDate(ctx, c, endChr) {
|
|
224
|
+
let startPtr = ctx.p++, unsafeSeparator;
|
|
225
|
+
if (!isDigit(c) ||
|
|
226
|
+
!isDigit(ctx.s.charCodeAt(ctx.p++)) ||
|
|
227
|
+
!isDigit(ctx.s.charCodeAt(ctx.p++)) ||
|
|
228
|
+
!isDigit(ctx.s.charCodeAt(ctx.p++))) {
|
|
229
|
+
return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
|
|
230
|
+
}
|
|
231
|
+
ctx.p += 5;
|
|
232
|
+
if (!isDigit(ctx.s.charCodeAt(ctx.p++)))
|
|
233
|
+
TomlError.x('invalid date-time: date part is malformed', ctx, startPtr);
|
|
234
|
+
if (ctx.p >= ctx.s.length || (((c = ctx.s.charCodeAt(ctx.p)) !== 0x20 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 0x54 /* T */ && c !== 0x74 /* t */)) {
|
|
235
|
+
let t = ctx.s.slice(startPtr, ctx.p);
|
|
236
|
+
return readDate(ctx, t, 3, false, startPtr);
|
|
237
|
+
}
|
|
238
|
+
if (ctx.s.charCodeAt(ctx.p += 3) !== 0x3a /* : */)
|
|
239
|
+
TomlError.x('invalid date-time: time part is malformed', ctx, startPtr);
|
|
240
|
+
if (ctx.s.charCodeAt(ctx.p += 3) === 0x3a /* : */)
|
|
241
|
+
ctx.p += 3;
|
|
242
|
+
if (ctx.s.charCodeAt(ctx.p) === 0x2e /* . */)
|
|
243
|
+
while (isDigit(ctx.s.charCodeAt(++ctx.p)))
|
|
244
|
+
;
|
|
245
|
+
if (c = ctx.s.charCodeAt(ctx.p)) {
|
|
246
|
+
if (c === 0x5a /* Z */ || c === 0x7a /* z */) {
|
|
247
|
+
let t = ctx.s.slice(startPtr, ++ctx.p);
|
|
248
|
+
return readDate(ctx, t, 1, unsafeSeparator, startPtr, '[+00:00]');
|
|
249
|
+
}
|
|
250
|
+
if (c === 0x2b /* + */ || c === 0x2d /* - */) {
|
|
251
|
+
// Temporal's ZonedDateTime is weird asf when it comes to dealing with traditional offsets...
|
|
252
|
+
// It's 1.2x faster to allocate a new string to pass to ZDT than use Instant.toZonedDateTimeISO
|
|
253
|
+
let t = ctx.s.slice(startPtr, ctx.p += 6);
|
|
254
|
+
return readDate(ctx, t, 1, unsafeSeparator, startPtr, !ctx.ld && ('[' + ctx.s.slice(ctx.p - 6, ctx.p) + ']'));
|
|
81
255
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
256
|
+
}
|
|
257
|
+
let t = ctx.s.slice(startPtr, ctx.p);
|
|
258
|
+
return readDate(ctx, t, 2, unsafeSeparator, startPtr);
|
|
259
|
+
}
|
|
260
|
+
function parseTime(ctx, c, endChr) {
|
|
261
|
+
let start = ctx.p;
|
|
262
|
+
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(++ctx.p))) {
|
|
263
|
+
return parseNumber(ctx, --ctx.p, c, 0, endChr);
|
|
264
|
+
}
|
|
265
|
+
if (ctx.s.charCodeAt(ctx.p += 4) === 0x3a /* : */)
|
|
266
|
+
ctx.p += 3;
|
|
267
|
+
if (ctx.s.charCodeAt(ctx.p) === 0x2e /* . */)
|
|
268
|
+
while (isDigit(ctx.s.charCodeAt(++ctx.p)))
|
|
269
|
+
;
|
|
270
|
+
let t = ctx.s.slice(start, ctx.p);
|
|
271
|
+
return readDate(ctx, t, 4, false, start);
|
|
272
|
+
}
|
|
273
|
+
function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
|
|
274
|
+
if (ctx.ld) {
|
|
275
|
+
let date = new TomlDate(str, type, unsafeDelim);
|
|
276
|
+
if (!date.isValid())
|
|
277
|
+
TomlError.x('invalid date', ctx, errPtr);
|
|
278
|
+
return date;
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
if (temporalSuffix)
|
|
282
|
+
str += temporalSuffix;
|
|
283
|
+
switch (type) {
|
|
284
|
+
case 1: return Temporal.ZonedDateTime.from(str);
|
|
285
|
+
case 2: return Temporal.PlainDateTime.from(str);
|
|
286
|
+
case 3: return Temporal.PlainDate.from(str);
|
|
287
|
+
case 4: return Temporal.PlainTime.from(str);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
catch (e) {
|
|
291
|
+
TomlError.x(e instanceof Error ? e.message : '' + e, ctx, errPtr);
|
|
292
|
+
}
|
|
100
293
|
}
|
|
@@ -29,7 +29,7 @@ import { parseKey } from './struct.js';
|
|
|
29
29
|
import { extractValue } from './extract.js';
|
|
30
30
|
import { skipVoid } from './util.js';
|
|
31
31
|
import { TomlError } from './error.js';
|
|
32
|
-
function peekTable(key, table, meta, type) {
|
|
32
|
+
function peekTable(ctx, key, table, meta, type) {
|
|
33
33
|
let t = table;
|
|
34
34
|
let m = meta;
|
|
35
35
|
let k;
|
|
@@ -37,7 +37,7 @@ function peekTable(key, table, meta, type) {
|
|
|
37
37
|
let state;
|
|
38
38
|
for (let i = 0; i < key.length; i++) {
|
|
39
39
|
if (i) {
|
|
40
|
-
t = hasOwn ? t[k] : (t[k] =
|
|
40
|
+
t = hasOwn ? t[k] : (t[k] = Object.create(null));
|
|
41
41
|
m = (state = m[k]).c;
|
|
42
42
|
if (type === 0 /* Type.DOTTED */ && (state.t === 1 /* Type.EXPLICIT */ || state.t === 2 /* Type.ARRAY */)) {
|
|
43
43
|
return null;
|
|
@@ -53,17 +53,19 @@ function peekTable(key, table, meta, type) {
|
|
|
53
53
|
return null;
|
|
54
54
|
}
|
|
55
55
|
if (!hasOwn) {
|
|
56
|
-
|
|
56
|
+
let unsafe = k === '__proto__';
|
|
57
|
+
if (ctx.uk && (unsafe || k === 'constructor'))
|
|
58
|
+
return false;
|
|
59
|
+
if (unsafe) {
|
|
57
60
|
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
|
|
58
61
|
Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
|
|
59
62
|
}
|
|
60
63
|
m[k] = {
|
|
61
64
|
t: i < key.length - 1 && type === 2 /* Type.ARRAY */
|
|
62
|
-
? 3 /* Type.ARRAY_DOTTED */
|
|
63
|
-
: type,
|
|
65
|
+
? 3 /* Type.ARRAY_DOTTED */ : type,
|
|
64
66
|
d: false,
|
|
65
67
|
i: 0,
|
|
66
|
-
c:
|
|
68
|
+
c: Object.create(null),
|
|
67
69
|
};
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -77,8 +79,8 @@ function peekTable(key, table, meta, type) {
|
|
|
77
79
|
state.d = true;
|
|
78
80
|
t[k] = [];
|
|
79
81
|
}
|
|
80
|
-
t[k].push(t =
|
|
81
|
-
state.c[state.i++] = (state = { t: 1 /* Type.EXPLICIT */, d: false, i: 0, c:
|
|
82
|
+
t[k].push(t = Object.create(null));
|
|
83
|
+
state.c[state.i++] = (state = { t: 1 /* Type.EXPLICIT */, d: false, i: 0, c: Object.create(null) });
|
|
82
84
|
}
|
|
83
85
|
if (state.d) {
|
|
84
86
|
// Redefining a table!
|
|
@@ -86,63 +88,77 @@ function peekTable(key, table, meta, type) {
|
|
|
86
88
|
}
|
|
87
89
|
state.d = true;
|
|
88
90
|
if (type === 1 /* Type.EXPLICIT */) {
|
|
89
|
-
t = hasOwn ? t[k] : (t[k] =
|
|
91
|
+
t = hasOwn ? t[k] : (t[k] = Object.create(null));
|
|
90
92
|
}
|
|
91
93
|
else if (type === 0 /* Type.DOTTED */ && hasOwn) {
|
|
92
94
|
return null;
|
|
93
95
|
}
|
|
94
96
|
return [k, t, state.c];
|
|
95
97
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
function validateTablePeek(ctx, peek, ptr) {
|
|
99
|
+
if (peek === null || ctx.uk === 2)
|
|
100
|
+
TomlError.x(peek === null
|
|
101
|
+
? 'trying to redefine an already defined table or value'
|
|
102
|
+
: 'document contains an unsafe property', ctx, ptr);
|
|
103
|
+
}
|
|
104
|
+
export function parse(toml, options = {}) {
|
|
105
|
+
let ctx = {
|
|
106
|
+
s: toml,
|
|
107
|
+
p: 0,
|
|
108
|
+
d: options.maxDepth ?? 1000,
|
|
109
|
+
bi: options.integersAsBigInt ?? false,
|
|
110
|
+
ld: options.useLegacyDate ?? true,
|
|
111
|
+
uk: options.unsafeKeyBehaviour === 'throw' ? 2 : options.unsafeKeyBehaviour === 'drop' ? 1 : 0,
|
|
112
|
+
};
|
|
113
|
+
let res = Object.create(null);
|
|
114
|
+
let meta = Object.create(null);
|
|
115
|
+
let tmp;
|
|
116
|
+
let skipping = false;
|
|
99
117
|
let tbl = res;
|
|
100
118
|
let m = meta;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
119
|
+
// BOM is allowed, skip.
|
|
120
|
+
// JS is UTF-16, so we have to check for the UTF-16 BOM instead of the UTF-8 BOM sequence!
|
|
121
|
+
if (toml.charCodeAt(0) === 0xfeff)
|
|
122
|
+
ctx.p++;
|
|
123
|
+
skipVoid(ctx);
|
|
124
|
+
while (ctx.p < toml.length) {
|
|
125
|
+
if (toml.charCodeAt(ctx.p) === 0x5b /* [ */) {
|
|
126
|
+
let isTableArray = toml.charCodeAt(++ctx.p) === 0x5b; /* [ */
|
|
127
|
+
tmp = ctx.p += +isTableArray;
|
|
128
|
+
skipping = false;
|
|
129
|
+
let k = parseKey(ctx, 0x5d /* ] */);
|
|
105
130
|
if (isTableArray) {
|
|
106
|
-
if (toml
|
|
107
|
-
|
|
108
|
-
toml: toml,
|
|
109
|
-
ptr: k[1] - 1,
|
|
110
|
-
});
|
|
131
|
+
if (toml.charCodeAt(ctx.p) !== 0x5d /* ] */) {
|
|
132
|
+
TomlError.x('expected end of table array declaration', ctx);
|
|
111
133
|
}
|
|
112
|
-
|
|
134
|
+
ctx.p++;
|
|
113
135
|
}
|
|
114
|
-
let p = peekTable(k
|
|
136
|
+
let p = peekTable(ctx, k, res, meta, isTableArray ? 2 /* Type.ARRAY */ : 1 /* Type.EXPLICIT */);
|
|
115
137
|
if (!p) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
138
|
+
validateTablePeek(ctx, p, tmp);
|
|
139
|
+
skipping = true;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
m = p[2];
|
|
143
|
+
tbl = p[1];
|
|
120
144
|
}
|
|
121
|
-
m = p[2];
|
|
122
|
-
tbl = p[1];
|
|
123
|
-
ptr = k[1];
|
|
124
145
|
}
|
|
125
146
|
else {
|
|
126
|
-
|
|
127
|
-
let
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
p[1][p[0]] = v[0];
|
|
136
|
-
ptr = v[1];
|
|
147
|
+
tmp = ctx.p;
|
|
148
|
+
let k = parseKey(ctx);
|
|
149
|
+
let p = peekTable(ctx, k, tbl, m, 0 /* Type.DOTTED */);
|
|
150
|
+
if (!p && !skipping)
|
|
151
|
+
validateTablePeek(ctx, p, tmp);
|
|
152
|
+
skipVoid(ctx, true, true);
|
|
153
|
+
let v = extractValue(ctx, void 0);
|
|
154
|
+
if (p && !skipping)
|
|
155
|
+
p[1][p[0]] = v;
|
|
137
156
|
}
|
|
138
|
-
|
|
139
|
-
if (toml
|
|
140
|
-
|
|
141
|
-
toml: toml,
|
|
142
|
-
ptr: ptr
|
|
143
|
-
});
|
|
157
|
+
skipVoid(ctx, true);
|
|
158
|
+
if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 0xa /* \n */ && (tmp !== 0xd /* \r */ || toml.charCodeAt(ctx.p + 1) !== 0xa /* \n */)) {
|
|
159
|
+
TomlError.x('each key-value declaration must be followed by an end-of-line', ctx);
|
|
144
160
|
}
|
|
145
|
-
|
|
161
|
+
skipVoid(ctx);
|
|
146
162
|
}
|
|
147
163
|
return res;
|
|
148
164
|
}
|