kimi-plugin-cc 2.0.8 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +21 -0
  4. package/README.md +5 -5
  5. package/agents/kimi-ask.md +1 -1
  6. package/agents/kimi-challenge.md +1 -1
  7. package/agents/kimi-rescue.md +1 -1
  8. package/agents/kimi-review.md +1 -1
  9. package/commands/ask.md +1 -1
  10. package/commands/challenge.md +1 -1
  11. package/commands/rescue.md +1 -1
  12. package/commands/review.md +1 -1
  13. package/dist/cli-client.js +9 -3
  14. package/dist/commands/ask.js +10 -6
  15. package/dist/commands/cli-helpers.js +53 -4
  16. package/dist/commands/pursue.js +2 -1
  17. package/dist/commands/rescue.js +12 -9
  18. package/dist/commands/result.js +3 -1
  19. package/dist/commands/review-gate.js +2 -1
  20. package/dist/commands/review.js +4 -3
  21. package/dist/commands/status.js +2 -2
  22. package/dist/commands/swarm.js +3 -1
  23. package/dist/hooks/config-safety.js +15 -7
  24. package/dist/job-store.js +36 -4
  25. package/dist/session-recovery.js +203 -0
  26. package/dist/vendor/smol-toml/date.js +50 -21
  27. package/dist/vendor/smol-toml/error.js +6 -2
  28. package/dist/vendor/smol-toml/extract.js +259 -66
  29. package/dist/vendor/smol-toml/parse.js +64 -48
  30. package/dist/vendor/smol-toml/primitive.js +107 -135
  31. package/dist/vendor/smol-toml/struct.js +106 -134
  32. package/dist/vendor/smol-toml/util.js +22 -78
  33. package/dist/version.js +1 -1
  34. package/docs/registry-releases.md +22 -1
  35. package/docs/safety.md +49 -2
  36. package/package.json +1 -1
  37. package/plugins/kimi-codex/.codex-plugin/plugin.json +1 -1
  38. package/plugins/kimi-codex/dist/cli-client.js +9 -3
  39. package/plugins/kimi-codex/dist/commands/ask.js +10 -6
  40. package/plugins/kimi-codex/dist/commands/cli-helpers.js +53 -4
  41. package/plugins/kimi-codex/dist/commands/pursue.js +2 -1
  42. package/plugins/kimi-codex/dist/commands/rescue.js +12 -9
  43. package/plugins/kimi-codex/dist/commands/result.js +3 -1
  44. package/plugins/kimi-codex/dist/commands/review-gate.js +2 -1
  45. package/plugins/kimi-codex/dist/commands/review.js +4 -3
  46. package/plugins/kimi-codex/dist/commands/status.js +2 -2
  47. package/plugins/kimi-codex/dist/commands/swarm.js +3 -1
  48. package/plugins/kimi-codex/dist/hooks/config-safety.js +15 -7
  49. package/plugins/kimi-codex/dist/job-store.js +36 -4
  50. package/plugins/kimi-codex/dist/session-recovery.js +203 -0
  51. package/plugins/kimi-codex/dist/vendor/smol-toml/date.js +50 -21
  52. package/plugins/kimi-codex/dist/vendor/smol-toml/error.js +6 -2
  53. package/plugins/kimi-codex/dist/vendor/smol-toml/extract.js +259 -66
  54. package/plugins/kimi-codex/dist/vendor/smol-toml/parse.js +64 -48
  55. package/plugins/kimi-codex/dist/vendor/smol-toml/primitive.js +107 -135
  56. package/plugins/kimi-codex/dist/vendor/smol-toml/struct.js +106 -134
  57. package/plugins/kimi-codex/dist/vendor/smol-toml/util.js +22 -78
  58. package/plugins/kimi-codex/dist/version.js +1 -1
  59. package/plugins/kimi-codex/skills/kimi-ask/SKILL.md +1 -1
  60. package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +1 -1
  61. package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +1 -1
  62. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +1 -1
@@ -25,155 +25,127 @@
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 { skipVoid } from './util.js';
29
- import { TomlDate } from './date.js';
30
28
  import { TomlError } from './error.js';
31
- let INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
32
- let FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
33
- let LEADING_ZERO = /^[+-]?0[0-9_]/;
34
- let ESCAPE_REGEX = /^[0-9a-f]{2,8}$/i;
35
- let ESC_MAP = {
36
- b: '\b',
37
- t: '\t',
38
- n: '\n',
39
- f: '\f',
40
- r: '\r',
41
- e: '\x1b',
42
- '"': '"',
43
- '\\': '\\',
44
- };
45
- export function parseString(str, ptr = 0, endPtr = str.length) {
46
- let isLiteral = str[ptr] === '\'';
47
- let isMultiline = str[ptr++] === str[ptr] && str[ptr] === str[ptr + 1];
29
+ /** @internal */
30
+ export function parseString(ctx) {
31
+ let startPtr = ctx.p;
32
+ let c = ctx.s.charCodeAt(ctx.p++);
33
+ let first = c;
34
+ let isLiteral = c === 0x27; /* ' */
35
+ let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
48
36
  if (isMultiline) {
49
- endPtr -= 2;
50
- if (str[ptr += 2] === '\r')
51
- ptr++;
52
- if (str[ptr] === '\n')
53
- ptr++;
37
+ // Trim initial newline
38
+ if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 0xa /* \n */)
39
+ ctx.p++;
40
+ else if (c === 0xd /* \r */ && ctx.s.charCodeAt(ctx.p + 1) === 0xa /* \n */)
41
+ ctx.p += 2;
54
42
  }
55
- let tmp = 0;
56
- let isEscape;
43
+ // For the record: it is not worth it to use a fast-path for literal strings using `indexOf`.
44
+ // Doing a char-by-char iteration ends up dispatching less instructions, for the same wall-clock runtime.
57
45
  let parsed = '';
58
- let sliceStart = ptr;
59
- while (ptr < endPtr - 1) {
60
- let c = str[ptr++];
61
- if (c === '\n' || (c === '\r' && str[ptr] === '\n')) {
62
- if (!isMultiline) {
63
- throw new TomlError('newlines are not allowed in strings', {
64
- toml: str,
65
- ptr: ptr - 1,
66
- });
46
+ let sliceStart = ctx.p;
47
+ // states:
48
+ // 0 - decoding
49
+ // 1 - decoding escape
50
+ // 2 - whitespace escape (no newline encountered yet, must fail on non-whitespace)
51
+ // 3 - whitespace escape (newline encountered, allowed to transition back to normal decode)
52
+ let state = 0;
53
+ for (; ctx.p < ctx.s.length; ctx.p++) {
54
+ c = ctx.s.charCodeAt(ctx.p);
55
+ // Deal with newlines first, since that simplifies control character checking and handling across all states
56
+ if (isMultiline && (c === 0xa /* \n */ || (c === 0xd /* \r */ && ctx.s.charCodeAt(ctx.p + 1) === 0xa /* \n */))) {
57
+ state = state && 3;
58
+ }
59
+ // Control characters are banned in TOML, so we throw an error if we encounter them
60
+ else if ((c < 0x20 && c !== 0x9 /* \t */) || c === 0x7f) {
61
+ TomlError.x('control characters are not allowed in strings', ctx);
62
+ }
63
+ // The string might terminate while we're parsing through a newline escape.
64
+ // It must have encountered a newline; otherwise, it'll simply fail in another branch.
65
+ else if ((!state || state === 3) && c === first && (!isMultiline || (ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first))) {
66
+ if (isMultiline) {
67
+ // If the string ends with 4-5 quotes, then the first 1-2 are part of the string
68
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
69
+ ctx.p++;
70
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
71
+ ctx.p++;
67
72
  }
73
+ // If we're in a newline escape still, then there's nothing to add.
74
+ if (!state) {
75
+ // Avoid a useless concat operation if the string can be used as-is.
76
+ let s = ctx.s.slice(sliceStart, ctx.p);
77
+ parsed = parsed ? parsed + s : s;
78
+ }
79
+ ctx.p += isMultiline ? 3 : 1;
80
+ return parsed;
68
81
  }
69
- else if ((c < '\x20' && c !== '\t') || c === '\x7f') {
70
- throw new TomlError('control characters are not allowed in strings', {
71
- toml: str,
72
- ptr: ptr - 1,
73
- });
82
+ // Baseline state; keep moving forward unless an escape sequence starts
83
+ else if (!state) {
84
+ if (!isLiteral && c === 0x5c /* \ */) {
85
+ parsed += ctx.s.slice(sliceStart, (sliceStart = ctx.p));
86
+ state = 1;
87
+ }
74
88
  }
75
- if (isEscape) {
76
- isEscape = false;
77
- if (c === 'x' || c === 'u' || c === 'U') {
78
- // Unicode escape
79
- let code = str.slice(ptr, (ptr += (c === 'x' ? 2 : c === 'u' ? 4 : 8)));
80
- if (!ESCAPE_REGEX.test(code)) {
81
- throw new TomlError('invalid unicode escape', {
82
- toml: str,
83
- ptr: tmp,
84
- });
89
+ else if (state === 1) {
90
+ if (c === 0x78 /* x */ || c === 0x75 /* u */ || c === 0x55 /* U */) { // Unicode escape
91
+ let errPtr = ctx.p++ - 1;
92
+ let value = 0;
93
+ let len = c === 0x78 /* x */ ? 2 : c === 0x75 /* u */ ? 4 : 8;
94
+ for (let j = 0; j < len; j++, ctx.p++) {
95
+ let hex = ctx.s.charCodeAt(ctx.p);
96
+ let digit =
97
+ /* 0-9 */ hex >= 0x30 && hex <= 0x39 ? hex - 0x30 :
98
+ /* A-F */ hex >= 0x41 && hex <= 0x46 ? hex - 0x41 + 10 :
99
+ /* a-f */ hex >= 0x61 && hex <= 0x66 ? hex - 0x61 + 10 : -1;
100
+ if (digit < 0)
101
+ TomlError.x('invalid non-hex character in unicode escape', ctx);
102
+ value = (value << 4) | digit;
85
103
  }
86
- try {
87
- parsed += String.fromCodePoint(parseInt(code, 16));
88
- }
89
- catch {
90
- throw new TomlError('invalid unicode escape', {
91
- toml: str,
92
- ptr: tmp,
93
- });
94
- }
95
- }
96
- else if (isMultiline && (c === '\n' || c === ' ' || c === '\t' || c === '\r')) {
97
- // Multiline escape
98
- ptr = skipVoid(str, ptr - 1, true);
99
- if (str[ptr] !== '\n' && str[ptr] !== '\r') {
100
- throw new TomlError('invalid escape: only line-ending whitespace may be escaped', {
101
- toml: str,
102
- ptr: tmp,
103
- });
104
+ // Because JS does bitwise on signed 32bit integers, all 0xfzzzzzzz values are actually seen as negative
105
+ if (value < 0 || value > 0x10ffff || (value >= 0xd800 && value <= 0xdfff)) {
106
+ TomlError.x('invalid unicode escape', ctx, errPtr);
104
107
  }
105
- ptr = skipVoid(str, ptr);
108
+ parsed += String.fromCodePoint(value);
109
+ sliceStart = ctx.p--;
110
+ state = 0;
106
111
  }
107
- else if (c in ESC_MAP) {
108
- // Classic escape
109
- parsed += ESC_MAP[c];
112
+ // Newline escape sequence. We only need to care about spaces and tabs; newlines are dealt with earlier
113
+ else if (isMultiline && (c === 0x20 || c === 0x9 /* \t */)) {
114
+ state = 2;
110
115
  }
116
+ // Basic escape sequence
111
117
  else {
112
- throw new TomlError('unrecognized escape sequence', {
113
- toml: str,
114
- ptr: tmp,
115
- });
118
+ if (c === 0x62 /* b */)
119
+ parsed += '\b';
120
+ else if (c === 0x74 /* t */)
121
+ parsed += '\t';
122
+ else if (c === 0x6e /* n */)
123
+ parsed += '\n';
124
+ else if (c === 0x66 /* f */)
125
+ parsed += '\f';
126
+ else if (c === 0x72 /* r */)
127
+ parsed += '\r';
128
+ else if (c === 0x65 /* e */)
129
+ parsed += '\x1b';
130
+ else if (c === 0x22 /* " */)
131
+ parsed += '"';
132
+ else if (c === 0x5c /* \ */)
133
+ parsed += '\\';
134
+ else
135
+ TomlError.x('unrecognised escape sequence', ctx);
136
+ sliceStart = ctx.p + 1;
137
+ state = 0;
116
138
  }
117
- sliceStart = ptr;
118
139
  }
119
- else if (!isLiteral && c === '\\') {
120
- tmp = ptr - 1;
121
- isEscape = true;
122
- parsed += str.slice(sliceStart, tmp);
140
+ // Newline escape continuation: keep moving forward until the first non-whitespace char
141
+ else if (c !== 0x20 && c !== 0x9 /* \t */) {
142
+ if (state === 2)
143
+ TomlError.x('invalid escape: only line-ending whitespace may be escaped', ctx, sliceStart);
144
+ // State cannot be zero, or we'd have branched earlier already.
145
+ // If it's a backslash, immediately transition to the escape state so it can be processed.
146
+ state = !isLiteral && c === 0x5c /* \ */ ? 1 : 0;
147
+ sliceStart = ctx.p;
123
148
  }
124
149
  }
125
- return parsed + str.slice(sliceStart, endPtr - 1);
126
- }
127
- export function parseValue(value, toml, ptr, integersAsBigInt) {
128
- // Constant values
129
- if (value === 'true')
130
- return true;
131
- if (value === 'false')
132
- return false;
133
- if (value === '-inf')
134
- return -Infinity;
135
- if (value === 'inf' || value === '+inf')
136
- return Infinity;
137
- if (value === 'nan' || value === '+nan' || value === '-nan')
138
- return NaN;
139
- // Avoid FP representation of -0
140
- if (value === '-0')
141
- return integersAsBigInt ? 0n : 0;
142
- // Numbers
143
- let isInt = INT_REGEX.test(value);
144
- if (isInt || FLOAT_REGEX.test(value)) {
145
- if (LEADING_ZERO.test(value)) {
146
- throw new TomlError('leading zeroes are not allowed', {
147
- toml: toml,
148
- ptr: ptr,
149
- });
150
- }
151
- value = value.replace(/_/g, '');
152
- let numeric = +value;
153
- if (isNaN(numeric)) {
154
- throw new TomlError('invalid number', {
155
- toml: toml,
156
- ptr: ptr,
157
- });
158
- }
159
- if (isInt) {
160
- if ((isInt = !Number.isSafeInteger(numeric)) && !integersAsBigInt) {
161
- throw new TomlError('integer value cannot be represented losslessly', {
162
- toml: toml,
163
- ptr: ptr,
164
- });
165
- }
166
- if (isInt || integersAsBigInt === true)
167
- numeric = BigInt(value);
168
- }
169
- return numeric;
170
- }
171
- const date = new TomlDate(value);
172
- if (!date.isValid()) {
173
- throw new TomlError('invalid value', {
174
- toml: toml,
175
- ptr: ptr,
176
- });
177
- }
178
- return date;
150
+ TomlError.x('unfinished string', ctx, startPtr);
179
151
  }
@@ -27,158 +27,130 @@
27
27
  */
28
28
  import { parseString } from './primitive.js';
29
29
  import { extractValue } from './extract.js';
30
- import { getStringEnd, indexOfNewline, skipComment, skipVoid } from './util.js';
30
+ import { skipVoid } from './util.js';
31
31
  import { TomlError } from './error.js';
32
- let KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/;
33
- export function parseKey(str, ptr, end = '=') {
34
- let dot = ptr - 1;
32
+ /** @internal */
33
+ export function parseKey(ctx, end = 0x3d /* = */) {
34
+ // States:
35
+ // 0: before first char
36
+ // 1: parsing bare key
37
+ // 2: after key component
38
+ let startPtr;
39
+ let state = 0;
35
40
  let parsed = [];
36
- let endPtr = str.indexOf(end, ptr);
37
- if (endPtr < 0) {
38
- throw new TomlError('incomplete key-value: cannot find end of key', {
39
- toml: str,
40
- ptr: ptr,
41
- });
42
- }
41
+ let sliceStart;
42
+ let c = ctx.s.charCodeAt(startPtr = ctx.p);
43
43
  do {
44
- let c = str[ptr = ++dot];
45
- // If it's whitespace, ignore
46
- if (c !== ' ' && c !== '\t') {
47
- // If it's a string
48
- if (c === '"' || c === '\'') {
49
- if (c === str[ptr + 1] && c === str[ptr + 2]) {
50
- throw new TomlError('multiline strings are not allowed in keys', {
51
- toml: str,
52
- ptr: ptr,
53
- });
54
- }
55
- let eos = getStringEnd(str, ptr);
56
- if (eos < 0) {
57
- throw new TomlError('unfinished string encountered', {
58
- toml: str,
59
- ptr: ptr,
60
- });
61
- }
62
- dot = str.indexOf('.', eos);
63
- let strEnd = str.slice(eos, dot < 0 || dot > endPtr ? endPtr : dot);
64
- let newLine = indexOfNewline(strEnd);
65
- if (newLine > -1) {
66
- throw new TomlError('newlines are not allowed in keys', {
67
- toml: str,
68
- ptr: ptr + dot + newLine,
69
- });
70
- }
71
- if (strEnd.trimStart()) {
72
- throw new TomlError('found extra tokens after the string part', {
73
- toml: str,
74
- ptr: eos,
75
- });
76
- }
77
- if (endPtr < eos) {
78
- endPtr = str.indexOf(end, eos);
79
- if (endPtr < 0) {
80
- throw new TomlError('incomplete key-value: cannot find end of key', {
81
- toml: str,
82
- ptr: ptr,
83
- });
84
- }
85
- }
86
- parsed.push(parseString(str, ptr, eos));
87
- }
88
- else {
89
- // Normal raw key part consumption and validation
90
- dot = str.indexOf('.', ptr);
91
- let part = str.slice(ptr, dot < 0 || dot > endPtr ? endPtr : dot);
92
- if (!KEY_PART_RE.test(part)) {
93
- throw new TomlError('only letter, numbers, dashes and underscores are allowed in keys', {
94
- toml: str,
95
- ptr: ptr,
96
- });
97
- }
98
- parsed.push(part.trimEnd());
44
+ // End of key
45
+ if (c === end) {
46
+ if (!state)
47
+ TomlError.x('unexpected end of key', ctx);
48
+ if (state === 1)
49
+ parsed.push(ctx.s.slice(sliceStart, ctx.p));
50
+ return ctx.p++, parsed;
51
+ }
52
+ // Dotted key separator
53
+ else if (c === 0x2e /* . */) {
54
+ if (!state)
55
+ TomlError.x('illegal empty bare key', ctx);
56
+ if (state === 1)
57
+ parsed.push(ctx.s.slice(sliceStart, ctx.p));
58
+ state = 0;
59
+ }
60
+ // Quoted key
61
+ else if (!state && (c === 0x22 /* " */ || c === 0x27 /* ' */)) {
62
+ if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2))
63
+ TomlError.x('illegal quoted key: multiline strings are not allowed', ctx);
64
+ parsed.push(parseString(ctx));
65
+ state = 2;
66
+ ctx.p--;
67
+ }
68
+ // Whitespace; no-op in state 0 and 2, end of bare key in state 1
69
+ else if (c === 0x20 || c === 0x9 /* \t */) {
70
+ if (state === 1) {
71
+ parsed.push(ctx.s.slice(sliceStart, ctx.p));
72
+ state = 2;
99
73
  }
100
74
  }
101
- // Until there's no more dot
102
- } while (dot + 1 && dot < endPtr);
103
- return [parsed, skipVoid(str, endPtr + 1, true, true)];
75
+ // If state is post-key, no character is allowed; otherwise ensure it's a bare-key component
76
+ else if (state === 2 || (c < 0x30 && c !== 0x2d /* - */) || (c > 0x39 && c < 0x41) || (c > 0x5a && c < 0x61 && c !== 0x5f /* _ */) || c > 0x7a) {
77
+ TomlError.x('illegal character in key', ctx);
78
+ }
79
+ // Illegal character
80
+ else if (!state) {
81
+ state = 1;
82
+ sliceStart = ctx.p;
83
+ }
84
+ } while (c = ctx.s.charCodeAt(++ctx.p));
85
+ TomlError.x('incomplete key-value: cannot find end of key', ctx, startPtr);
104
86
  }
105
- export function parseInlineTable(str, ptr, depth, integersAsBigInt) {
106
- let res = {};
87
+ /** @internal */
88
+ export function parseInlineTable(ctx) {
89
+ let startPtr = ctx.p++;
90
+ let res = Object.create(null);
107
91
  let seen = new Set();
108
92
  let c;
109
- ptr++;
110
- while ((c = str[ptr++]) !== '}' && c) {
111
- if (c === ',') {
112
- throw new TomlError('expected value, found comma', {
113
- toml: str,
114
- ptr: ptr - 1,
115
- });
93
+ while (ctx.p < ctx.s.length) {
94
+ skipVoid(ctx);
95
+ if ((c = ctx.s.charCodeAt(ctx.p)) === 0x7d /* } */) {
96
+ ctx.p++;
97
+ return res;
116
98
  }
117
- else if (c === '#')
118
- ptr = skipComment(str, ptr);
119
- else if (c !== ' ' && c !== '\t' && c !== '\n' && c !== '\r') {
120
- let k;
121
- let t = res;
122
- let hasOwn = false;
123
- let [key, keyEndPtr] = parseKey(str, ptr - 1);
124
- for (let i = 0; i < key.length; i++) {
125
- if (i)
126
- t = hasOwn ? t[k] : (t[k] = {});
127
- k = key[i];
128
- if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== 'object' || seen.has(t[k]))) {
129
- throw new TomlError('trying to redefine an already defined value', {
130
- toml: str,
131
- ptr: ptr,
132
- });
133
- }
134
- if (!hasOwn && k === '__proto__') {
135
- Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
136
- }
99
+ let k;
100
+ let t = res;
101
+ let hasOwn = false;
102
+ let errPtr = ctx.p;
103
+ let key = parseKey(ctx);
104
+ for (let i = 0; i < key.length; i++) {
105
+ if (i)
106
+ t = hasOwn ? t[k] : (t[k] = Object.create(null));
107
+ k = key[i];
108
+ if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== 'object' || seen.has(t[k]))) {
109
+ TomlError.x('trying to redefine an already defined value', ctx, errPtr);
110
+ }
111
+ let unsafe = k === '__proto__';
112
+ if (ctx.uk && (unsafe || k === 'constructor')) {
113
+ t = ctx.uk !== 1 && TomlError.x('document contains an unsafe property', ctx, errPtr);
114
+ break;
137
115
  }
138
- if (hasOwn) {
139
- throw new TomlError('trying to redefine an already defined value', {
140
- toml: str,
141
- ptr: ptr,
142
- });
116
+ if (!hasOwn && unsafe) {
117
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
143
118
  }
144
- let [value, valueEndPtr] = extractValue(str, keyEndPtr, '}', depth - 1, integersAsBigInt);
119
+ }
120
+ if (hasOwn) {
121
+ TomlError.x('trying to redefine an already defined value', ctx, errPtr);
122
+ }
123
+ skipVoid(ctx, true, true);
124
+ let value = extractValue(ctx, 0x7d /* } */);
125
+ if (t && typeof (t[k] = value) === 'object')
145
126
  seen.add(value);
146
- t[k] = value;
147
- ptr = valueEndPtr;
127
+ skipVoid(ctx);
128
+ if ((c = ctx.s.charCodeAt(ctx.p++)) === 0x7d /* } */) {
129
+ return res;
148
130
  }
131
+ if (c !== 0x2c /* , */)
132
+ TomlError.x('expected comma or end of structure', ctx, ctx.p - 1);
149
133
  }
150
- if (!c) {
151
- throw new TomlError('unfinished table encountered', {
152
- toml: str,
153
- ptr: ptr,
154
- });
155
- }
156
- return [res, ptr];
134
+ TomlError.x('unfinished table', ctx, startPtr);
157
135
  }
158
- export function parseArray(str, ptr, depth, integersAsBigInt) {
136
+ /** @internal */
137
+ export function parseArray(ctx) {
138
+ let startPtr = ctx.p++;
159
139
  let res = [];
160
140
  let c;
161
- ptr++;
162
- while ((c = str[ptr++]) !== ']' && c) {
163
- if (c === ',') {
164
- throw new TomlError('expected value, found comma', {
165
- toml: str,
166
- ptr: ptr - 1,
167
- });
141
+ while (ctx.p < ctx.s.length) {
142
+ skipVoid(ctx);
143
+ if ((c = ctx.s.charCodeAt(ctx.p)) === 0x5d /* ] */) {
144
+ ctx.p++;
145
+ return res;
168
146
  }
169
- else if (c === '#')
170
- ptr = skipComment(str, ptr);
171
- else if (c !== ' ' && c !== '\t' && c !== '\n' && c !== '\r') {
172
- let e = extractValue(str, ptr - 1, ']', depth - 1, integersAsBigInt);
173
- res.push(e[0]);
174
- ptr = e[1];
147
+ res.push(extractValue(ctx, 0x5d /* ] */));
148
+ skipVoid(ctx);
149
+ if ((c = ctx.s.charCodeAt(ctx.p++)) === 0x5d /* ] */) {
150
+ return res;
175
151
  }
152
+ if (c !== 0x2c /* , */)
153
+ TomlError.x('expected comma or end of structure', ctx, ctx.p - 1);
176
154
  }
177
- if (!c) {
178
- throw new TomlError('unfinished array encountered', {
179
- toml: str,
180
- ptr: ptr,
181
- });
182
- }
183
- return [res, ptr];
155
+ TomlError.x('unfinished array', ctx, startPtr);
184
156
  }
@@ -26,88 +26,32 @@
26
26
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
  import { TomlError } from './error.js';
29
- function isEscaped(str, ptr) {
30
- let i = 0;
31
- while (str[ptr - ++i] === '\\')
32
- ;
33
- return --i && (i % 2);
34
- }
35
- export function indexOfNewline(str, start = 0, end = str.length) {
36
- let idx = str.indexOf('\n', start);
37
- if (str[idx - 1] === '\r')
38
- idx--;
39
- return idx <= end ? idx : -1;
40
- }
41
- export function skipComment(str, ptr) {
42
- for (let i = ptr; i < str.length; i++) {
43
- let c = str[i];
44
- if (c === '\n')
45
- return i;
46
- if (c === '\r' && str[i + 1] === '\n')
47
- return i + 1;
48
- if ((c < '\x20' && c !== '\t') || c === '\x7f') {
49
- throw new TomlError('control characters are not allowed in comments', {
50
- toml: str,
51
- ptr: ptr,
52
- });
53
- }
54
- }
55
- return str.length;
56
- }
57
- export function skipVoid(str, ptr, banNewLines, banComments) {
58
- let c;
59
- while (1) {
60
- while ((c = str[ptr]) === ' ' || c === '\t' || (!banNewLines && (c === '\n' || c === '\r' && str[ptr + 1] === '\n')))
61
- ptr++;
62
- // Tucking the return statement here would save 5 characters >:)
63
- // But TypeScript fails to detect there is no way to exit the loop so it complains about the lack of final return
64
- if (banComments || c !== '#')
29
+ /** @internal */
30
+ export function skipComment(ctx) {
31
+ for (; ctx.p < ctx.s.length; ctx.p++) {
32
+ let c = ctx.s.charCodeAt(ctx.p);
33
+ if (c === 0xa /* \n */)
34
+ break;
35
+ if (c === 0xd /* \r */ && ctx.s.charCodeAt(ctx.p + 1) === 0xa /* \n */) {
36
+ ctx.p++;
65
37
  break;
66
- ptr = skipComment(str, ptr);
67
- }
68
- return ptr;
69
- }
70
- export function skipUntil(str, ptr, sep, end, banNewLines = false) {
71
- if (!end) {
72
- ptr = indexOfNewline(str, ptr);
73
- return ptr < 0 ? str.length : ptr;
74
- }
75
- for (let i = ptr; i < str.length; i++) {
76
- let c = str[i];
77
- if (c === '#') {
78
- i = indexOfNewline(str, i);
79
- if (i < 0)
80
- break;
81
- }
82
- else if (c === sep) {
83
- return i + 1;
84
38
  }
85
- else if (c === end || (banNewLines && (c === '\n' || (c === '\r' && str[i + 1] === '\n')))) {
86
- return i;
39
+ if ((c < 0x20 && c !== 0x9 /* \t */) || c === 0x7f) {
40
+ TomlError.x('control characters are not allowed in comments', ctx);
87
41
  }
88
42
  }
89
- throw new TomlError('cannot find end of structure', {
90
- toml: str,
91
- ptr: ptr
92
- });
93
43
  }
94
- export function getStringEnd(str, seek) {
95
- let first = str[seek];
96
- let target = first === str[seek + 1] && str[seek + 1] === str[seek + 2]
97
- ? str.slice(seek, seek + 3)
98
- : first;
99
- seek += target.length - 1;
100
- do
101
- seek = str.indexOf(target, ++seek);
102
- while (seek > -1 && first !== "'" && isEscaped(str, seek));
103
- if (seek > -1) {
104
- seek += target.length;
105
- if (target.length > 1) {
106
- if (str[seek] === first)
107
- seek++;
108
- if (str[seek] === first)
109
- seek++;
110
- }
44
+ /** @internal */
45
+ export function skipVoid(ctx, banNewLines, banComments) {
46
+ let c;
47
+ while (ctx.p < ctx.s.length) {
48
+ while (ctx.p < ctx.s.length && ((c = ctx.s.charCodeAt(ctx.p)) === 0x20 ||
49
+ c === 0x9 /* \t */ ||
50
+ (!banNewLines &&
51
+ (c === 0xa /* \n */ || (c === 0xd /* \r */ && ctx.s.charCodeAt(ctx.p + 1) === 0xa /* \n */)))))
52
+ ctx.p++;
53
+ if (banComments || c !== 0x23 /* # */)
54
+ break;
55
+ skipComment(ctx);
111
56
  }
112
- return seek;
113
57
  }
package/dist/version.js CHANGED
@@ -4,4 +4,4 @@
4
4
  // and AGENTS.md on every release. A future improvement would read this from
5
5
  // package.json at build time, but that adds a build-step dependency we
6
6
  // don't want yet.
7
- export const KIMI_PLUGIN_CC_VERSION = "2.0.8";
7
+ export const KIMI_PLUGIN_CC_VERSION = "2.2.0";