kimi-plugin-cc 2.0.7

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 (190) hide show
  1. package/.agents/plugins/marketplace.json +20 -0
  2. package/.claude-plugin/marketplace.json +16 -0
  3. package/.claude-plugin/plugin.json +32 -0
  4. package/CHANGELOG.md +1096 -0
  5. package/LICENSE +201 -0
  6. package/README.md +772 -0
  7. package/agents/kimi-ask.md +82 -0
  8. package/agents/kimi-challenge.md +82 -0
  9. package/agents/kimi-pursue.md +91 -0
  10. package/agents/kimi-rescue.md +85 -0
  11. package/agents/kimi-review.md +82 -0
  12. package/agents/kimi-swarm-write.md +92 -0
  13. package/agents/kimi-swarm.md +83 -0
  14. package/commands/README.md +16 -0
  15. package/commands/ask.md +32 -0
  16. package/commands/cancel.md +17 -0
  17. package/commands/challenge.md +29 -0
  18. package/commands/pursue.md +37 -0
  19. package/commands/replay.md +13 -0
  20. package/commands/rescue.md +32 -0
  21. package/commands/result.md +13 -0
  22. package/commands/review.md +29 -0
  23. package/commands/setup.md +23 -0
  24. package/commands/status.md +13 -0
  25. package/commands/swarm.md +38 -0
  26. package/dist/background-spawn.js +224 -0
  27. package/dist/cli-cancellation.js +43 -0
  28. package/dist/cli-client.js +845 -0
  29. package/dist/commands/ask.js +327 -0
  30. package/dist/commands/cancel.js +178 -0
  31. package/dist/commands/cli-helpers.js +112 -0
  32. package/dist/commands/models.js +140 -0
  33. package/dist/commands/not-implemented.js +4 -0
  34. package/dist/commands/pursue.js +311 -0
  35. package/dist/commands/registry.js +87 -0
  36. package/dist/commands/repair-sessions.js +159 -0
  37. package/dist/commands/replay.js +123 -0
  38. package/dist/commands/rescue.js +333 -0
  39. package/dist/commands/result.js +58 -0
  40. package/dist/commands/review-gate.js +393 -0
  41. package/dist/commands/review.js +218 -0
  42. package/dist/commands/setup.js +1132 -0
  43. package/dist/commands/status.js +27 -0
  44. package/dist/commands/swarm.js +576 -0
  45. package/dist/commands/worker.js +31 -0
  46. package/dist/companion.js +114 -0
  47. package/dist/config.js +22 -0
  48. package/dist/errors.js +40 -0
  49. package/dist/git.js +215 -0
  50. package/dist/hooks/approval-hook.js +112 -0
  51. package/dist/hooks/approval-policy.js +254 -0
  52. package/dist/hooks/config-safety.js +637 -0
  53. package/dist/hooks/install-paths.js +504 -0
  54. package/dist/hooks/install.js +281 -0
  55. package/dist/hooks/managed-block.js +745 -0
  56. package/dist/hooks/review-gate-stop.js +19 -0
  57. package/dist/job-store.js +559 -0
  58. package/dist/jobs.js +202 -0
  59. package/dist/kimi-command.js +72 -0
  60. package/dist/kimi-engine.js +624 -0
  61. package/dist/kimi-errors.js +220 -0
  62. package/dist/kimi-home.js +9 -0
  63. package/dist/kimi-timeouts.js +68 -0
  64. package/dist/kimi-version-probe.js +1410 -0
  65. package/dist/logging.js +22 -0
  66. package/dist/native-v2-preflight.js +417 -0
  67. package/dist/package.json +1 -0
  68. package/dist/parsing.js +553 -0
  69. package/dist/paths.js +27 -0
  70. package/dist/plugin-data.js +98 -0
  71. package/dist/process-tree.js +448 -0
  72. package/dist/render.js +159 -0
  73. package/dist/rescue-approval.js +951 -0
  74. package/dist/schemas/review-gate-output.js +43 -0
  75. package/dist/session-title.js +293 -0
  76. package/dist/stream-json.js +498 -0
  77. package/dist/types.js +1 -0
  78. package/dist/vendor/shell-quote/LICENSE +24 -0
  79. package/dist/vendor/shell-quote/index.js +1 -0
  80. package/dist/vendor/shell-quote/parse.js +229 -0
  81. package/dist/vendor/smol-toml/LICENSE +24 -0
  82. package/dist/vendor/smol-toml/date.js +127 -0
  83. package/dist/vendor/smol-toml/error.js +63 -0
  84. package/dist/vendor/smol-toml/extract.js +100 -0
  85. package/dist/vendor/smol-toml/parse.js +148 -0
  86. package/dist/vendor/smol-toml/primitive.js +179 -0
  87. package/dist/vendor/smol-toml/struct.js +184 -0
  88. package/dist/vendor/smol-toml/util.js +113 -0
  89. package/dist/version.js +7 -0
  90. package/docs/migration.md +215 -0
  91. package/docs/models.md +82 -0
  92. package/docs/registry-releases.md +70 -0
  93. package/docs/safety.md +318 -0
  94. package/docs/session-visibility.md +32 -0
  95. package/hooks/README.md +9 -0
  96. package/hooks/hooks.json +16 -0
  97. package/package.json +67 -0
  98. package/plugins/kimi-codex/.codex-plugin/plugin.json +39 -0
  99. package/plugins/kimi-codex/dist/background-spawn.js +224 -0
  100. package/plugins/kimi-codex/dist/cli-cancellation.js +43 -0
  101. package/plugins/kimi-codex/dist/cli-client.js +845 -0
  102. package/plugins/kimi-codex/dist/commands/ask.js +327 -0
  103. package/plugins/kimi-codex/dist/commands/cancel.js +178 -0
  104. package/plugins/kimi-codex/dist/commands/cli-helpers.js +112 -0
  105. package/plugins/kimi-codex/dist/commands/models.js +140 -0
  106. package/plugins/kimi-codex/dist/commands/not-implemented.js +4 -0
  107. package/plugins/kimi-codex/dist/commands/pursue.js +311 -0
  108. package/plugins/kimi-codex/dist/commands/registry.js +87 -0
  109. package/plugins/kimi-codex/dist/commands/repair-sessions.js +159 -0
  110. package/plugins/kimi-codex/dist/commands/replay.js +123 -0
  111. package/plugins/kimi-codex/dist/commands/rescue.js +333 -0
  112. package/plugins/kimi-codex/dist/commands/result.js +58 -0
  113. package/plugins/kimi-codex/dist/commands/review-gate.js +393 -0
  114. package/plugins/kimi-codex/dist/commands/review.js +218 -0
  115. package/plugins/kimi-codex/dist/commands/setup.js +1132 -0
  116. package/plugins/kimi-codex/dist/commands/status.js +27 -0
  117. package/plugins/kimi-codex/dist/commands/swarm.js +576 -0
  118. package/plugins/kimi-codex/dist/commands/worker.js +31 -0
  119. package/plugins/kimi-codex/dist/companion.js +114 -0
  120. package/plugins/kimi-codex/dist/config.js +22 -0
  121. package/plugins/kimi-codex/dist/errors.js +40 -0
  122. package/plugins/kimi-codex/dist/git.js +215 -0
  123. package/plugins/kimi-codex/dist/hooks/approval-hook.js +112 -0
  124. package/plugins/kimi-codex/dist/hooks/approval-policy.js +254 -0
  125. package/plugins/kimi-codex/dist/hooks/config-safety.js +637 -0
  126. package/plugins/kimi-codex/dist/hooks/install-paths.js +504 -0
  127. package/plugins/kimi-codex/dist/hooks/install.js +281 -0
  128. package/plugins/kimi-codex/dist/hooks/managed-block.js +745 -0
  129. package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +19 -0
  130. package/plugins/kimi-codex/dist/job-store.js +559 -0
  131. package/plugins/kimi-codex/dist/jobs.js +202 -0
  132. package/plugins/kimi-codex/dist/kimi-command.js +72 -0
  133. package/plugins/kimi-codex/dist/kimi-engine.js +624 -0
  134. package/plugins/kimi-codex/dist/kimi-errors.js +220 -0
  135. package/plugins/kimi-codex/dist/kimi-home.js +9 -0
  136. package/plugins/kimi-codex/dist/kimi-timeouts.js +68 -0
  137. package/plugins/kimi-codex/dist/kimi-version-probe.js +1410 -0
  138. package/plugins/kimi-codex/dist/logging.js +22 -0
  139. package/plugins/kimi-codex/dist/native-v2-preflight.js +417 -0
  140. package/plugins/kimi-codex/dist/package.json +1 -0
  141. package/plugins/kimi-codex/dist/parsing.js +553 -0
  142. package/plugins/kimi-codex/dist/paths.js +27 -0
  143. package/plugins/kimi-codex/dist/plugin-data.js +98 -0
  144. package/plugins/kimi-codex/dist/process-tree.js +448 -0
  145. package/plugins/kimi-codex/dist/render.js +159 -0
  146. package/plugins/kimi-codex/dist/rescue-approval.js +951 -0
  147. package/plugins/kimi-codex/dist/schemas/review-gate-output.js +43 -0
  148. package/plugins/kimi-codex/dist/session-title.js +293 -0
  149. package/plugins/kimi-codex/dist/stream-json.js +498 -0
  150. package/plugins/kimi-codex/dist/types.js +1 -0
  151. package/plugins/kimi-codex/dist/vendor/shell-quote/LICENSE +24 -0
  152. package/plugins/kimi-codex/dist/vendor/shell-quote/index.js +1 -0
  153. package/plugins/kimi-codex/dist/vendor/shell-quote/parse.js +229 -0
  154. package/plugins/kimi-codex/dist/vendor/smol-toml/LICENSE +24 -0
  155. package/plugins/kimi-codex/dist/vendor/smol-toml/date.js +127 -0
  156. package/plugins/kimi-codex/dist/vendor/smol-toml/error.js +63 -0
  157. package/plugins/kimi-codex/dist/vendor/smol-toml/extract.js +100 -0
  158. package/plugins/kimi-codex/dist/vendor/smol-toml/parse.js +148 -0
  159. package/plugins/kimi-codex/dist/vendor/smol-toml/primitive.js +179 -0
  160. package/plugins/kimi-codex/dist/vendor/smol-toml/struct.js +184 -0
  161. package/plugins/kimi-codex/dist/vendor/smol-toml/util.js +113 -0
  162. package/plugins/kimi-codex/dist/version.js +7 -0
  163. package/plugins/kimi-codex/scripts/companion.sh +37 -0
  164. package/plugins/kimi-codex/scripts/review-gate-hook.sh +32 -0
  165. package/plugins/kimi-codex/skills/kimi-ask/SKILL.md +31 -0
  166. package/plugins/kimi-codex/skills/kimi-ask/agents/openai.yaml +6 -0
  167. package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +25 -0
  168. package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +6 -0
  169. package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +31 -0
  170. package/plugins/kimi-codex/skills/kimi-challenge/agents/openai.yaml +6 -0
  171. package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +30 -0
  172. package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +6 -0
  173. package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +25 -0
  174. package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +6 -0
  175. package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +30 -0
  176. package/plugins/kimi-codex/skills/kimi-rescue/agents/openai.yaml +6 -0
  177. package/plugins/kimi-codex/skills/kimi-result/SKILL.md +25 -0
  178. package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +6 -0
  179. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +31 -0
  180. package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +6 -0
  181. package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +32 -0
  182. package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +6 -0
  183. package/plugins/kimi-codex/skills/kimi-status/SKILL.md +25 -0
  184. package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +6 -0
  185. package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +31 -0
  186. package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +6 -0
  187. package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +32 -0
  188. package/plugins/kimi-codex/skills/kimi-swarm-write/agents/openai.yaml +6 -0
  189. package/scripts/companion.sh +37 -0
  190. package/scripts/review-gate-hook.sh +32 -0
@@ -0,0 +1,229 @@
1
+ // @ts-nocheck
2
+ // Vendored from shell-quote 1.8.3 with the upstream 1.9.0 linear-finalization fix.
3
+ // MIT, James Halliday. See ./LICENSE and ./README.md for provenance.
4
+ 'use strict';
5
+ // '<(' is process substitution operator and
6
+ // can be parsed the same as control operator
7
+ var CONTROL = '(?:' + [
8
+ '\\|\\|',
9
+ '\\&\\&',
10
+ ';;',
11
+ '\\|\\&',
12
+ '\\<\\(',
13
+ '\\<\\<\\<',
14
+ '>>',
15
+ '>\\&',
16
+ '<\\&',
17
+ '[&;()|<>]'
18
+ ].join('|') + ')';
19
+ var controlRE = new RegExp('^' + CONTROL + '$');
20
+ var META = '|&;()<> \\t';
21
+ var SINGLE_QUOTE = '"((\\\\"|[^"])*?)"';
22
+ var DOUBLE_QUOTE = '\'((\\\\\'|[^\'])*?)\'';
23
+ var hash = /^#$/;
24
+ var SQ = "'";
25
+ var DQ = '"';
26
+ var DS = '$';
27
+ var TOKEN = '';
28
+ var mult = 0x100000000; // Math.pow(16, 8);
29
+ for (var i = 0; i < 4; i++) {
30
+ TOKEN += (mult * Math.random()).toString(16);
31
+ }
32
+ var startsWithToken = new RegExp('^' + TOKEN);
33
+ function matchAll(s, r) {
34
+ var origIndex = r.lastIndex;
35
+ var matches = [];
36
+ var matchObj;
37
+ while ((matchObj = r.exec(s))) {
38
+ matches.push(matchObj);
39
+ if (r.lastIndex === matchObj.index) {
40
+ r.lastIndex += 1;
41
+ }
42
+ }
43
+ r.lastIndex = origIndex;
44
+ return matches;
45
+ }
46
+ function getVar(env, pre, key) {
47
+ var r = typeof env === 'function' ? env(key) : env[key];
48
+ if (typeof r === 'undefined' && key != '') {
49
+ r = '';
50
+ }
51
+ else if (typeof r === 'undefined') {
52
+ r = '$';
53
+ }
54
+ if (typeof r === 'object') {
55
+ return pre + TOKEN + JSON.stringify(r) + TOKEN;
56
+ }
57
+ return pre + r;
58
+ }
59
+ function parseInternal(string, env, opts) {
60
+ if (!opts) {
61
+ opts = {};
62
+ }
63
+ var BS = opts.escape || '\\';
64
+ var BAREWORD = '(\\' + BS + '[\'"' + META + ']|[^\\s\'"' + META + '])+';
65
+ var chunker = new RegExp([
66
+ '(' + CONTROL + ')', // control chars
67
+ '(' + BAREWORD + '|' + SINGLE_QUOTE + '|' + DOUBLE_QUOTE + ')+'
68
+ ].join('|'), 'g');
69
+ var matches = matchAll(string, chunker);
70
+ if (matches.length === 0) {
71
+ return [];
72
+ }
73
+ if (!env) {
74
+ env = {};
75
+ }
76
+ var commented = false;
77
+ return matches.map(function (match) {
78
+ var s = match[0];
79
+ if (!s || commented) {
80
+ return void undefined;
81
+ }
82
+ if (controlRE.test(s)) {
83
+ return { op: s };
84
+ }
85
+ // Hand-written scanner/parser for Bash quoting rules:
86
+ //
87
+ // 1. inside single quotes, all characters are printed literally.
88
+ // 2. inside double quotes, all characters are printed literally
89
+ // except variables prefixed by '$' and backslashes followed by
90
+ // either a double quote or another backslash.
91
+ // 3. outside of any quotes, backslashes are treated as escape
92
+ // characters and not printed (unless they are themselves escaped)
93
+ // 4. quote context can switch mid-token if there is no whitespace
94
+ // between the two quote contexts (e.g. all'one'"token" parses as
95
+ // "allonetoken")
96
+ var quote = false;
97
+ var esc = false;
98
+ var out = '';
99
+ var isGlob = false;
100
+ var i;
101
+ function parseEnvVar() {
102
+ i += 1;
103
+ var varend;
104
+ var varname;
105
+ var char = s.charAt(i);
106
+ if (char === '{') {
107
+ i += 1;
108
+ if (s.charAt(i) === '}') {
109
+ throw new Error('Bad substitution: ' + s.slice(i - 2, i + 1));
110
+ }
111
+ varend = s.indexOf('}', i);
112
+ if (varend < 0) {
113
+ throw new Error('Bad substitution: ' + s.slice(i));
114
+ }
115
+ varname = s.slice(i, varend);
116
+ i = varend;
117
+ }
118
+ else if ((/[*@#?$!_-]/).test(char)) {
119
+ varname = char;
120
+ i += 1;
121
+ }
122
+ else {
123
+ var slicedFromI = s.slice(i);
124
+ varend = slicedFromI.match(/[^\w\d_]/);
125
+ if (!varend) {
126
+ varname = slicedFromI;
127
+ i = s.length;
128
+ }
129
+ else {
130
+ varname = slicedFromI.slice(0, varend.index);
131
+ i += varend.index - 1;
132
+ }
133
+ }
134
+ return getVar(env, '', varname);
135
+ }
136
+ for (i = 0; i < s.length; i++) {
137
+ var c = s.charAt(i);
138
+ isGlob = isGlob || (!quote && (c === '*' || c === '?'));
139
+ if (esc) {
140
+ out += c;
141
+ esc = false;
142
+ }
143
+ else if (quote) {
144
+ if (c === quote) {
145
+ quote = false;
146
+ }
147
+ else if (quote == SQ) {
148
+ out += c;
149
+ }
150
+ else { // Double quote
151
+ if (c === BS) {
152
+ i += 1;
153
+ c = s.charAt(i);
154
+ if (c === DQ || c === BS || c === DS) {
155
+ out += c;
156
+ }
157
+ else {
158
+ out += BS + c;
159
+ }
160
+ }
161
+ else if (c === DS) {
162
+ out += parseEnvVar();
163
+ }
164
+ else {
165
+ out += c;
166
+ }
167
+ }
168
+ }
169
+ else if (c === DQ || c === SQ) {
170
+ quote = c;
171
+ }
172
+ else if (controlRE.test(c)) {
173
+ return { op: s };
174
+ }
175
+ else if (hash.test(c)) {
176
+ commented = true;
177
+ var commentObj = { comment: string.slice(match.index + i + 1) };
178
+ if (out.length) {
179
+ return [out, commentObj];
180
+ }
181
+ return [commentObj];
182
+ }
183
+ else if (c === BS) {
184
+ esc = true;
185
+ }
186
+ else if (c === DS) {
187
+ out += parseEnvVar();
188
+ }
189
+ else {
190
+ out += c;
191
+ }
192
+ }
193
+ if (isGlob) {
194
+ return { op: 'glob', pattern: out };
195
+ }
196
+ return out;
197
+ }).reduce(function (prev, arg) {
198
+ if (typeof arg === 'undefined') {
199
+ return prev;
200
+ }
201
+ [].concat(arg).forEach(function (entry) {
202
+ prev[prev.length] = entry;
203
+ });
204
+ return prev;
205
+ }, []);
206
+ }
207
+ export function parse(s, env, opts) {
208
+ var mapped = parseInternal(s, env, opts);
209
+ if (typeof env !== 'function') {
210
+ return mapped;
211
+ }
212
+ return mapped.reduce(function (acc, value) {
213
+ if (typeof value === 'object') {
214
+ acc[acc.length] = value;
215
+ return acc;
216
+ }
217
+ var xs = value.split(RegExp('(' + TOKEN + '.*?' + TOKEN + ')', 'g'));
218
+ if (xs.length === 1) {
219
+ acc[acc.length] = xs[0];
220
+ return acc;
221
+ }
222
+ xs.filter(Boolean).forEach(function (x) {
223
+ acc[acc.length] = startsWithToken.test(x)
224
+ ? JSON.parse(x.split(TOKEN)[1])
225
+ : x;
226
+ });
227
+ return acc;
228
+ }, []);
229
+ }
@@ -0,0 +1,24 @@
1
+ Copyright (c) Squirrel Chat et al., All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this
7
+ list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright notice,
9
+ this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ 3. Neither the name of the copyright holder nor the names of its contributors
12
+ may be used to endorse or promote products derived from this software without
13
+ specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,127 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ let DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
29
+ export class TomlDate extends Date {
30
+ #hasDate = false;
31
+ #hasTime = false;
32
+ #offset = null;
33
+ constructor(date) {
34
+ let hasDate = true;
35
+ let hasTime = true;
36
+ let offset = 'Z';
37
+ if (typeof date === 'string') {
38
+ let match = date.match(DATE_TIME_RE);
39
+ if (match) {
40
+ if (!match[1]) {
41
+ hasDate = false;
42
+ date = `0000-01-01T${date}`;
43
+ }
44
+ hasTime = !!match[2];
45
+ // Make sure to use T instead of a space. Breaks in case of extreme values otherwise.
46
+ hasTime && date[10] === ' ' && (date = date.replace(' ', 'T'));
47
+ // Do not allow rollover hours.
48
+ if (match[2] && +match[2] > 23) {
49
+ date = '';
50
+ }
51
+ else {
52
+ offset = match[3] || null;
53
+ date = date.toUpperCase();
54
+ if (!offset && hasTime)
55
+ date += 'Z';
56
+ }
57
+ }
58
+ else {
59
+ date = '';
60
+ }
61
+ }
62
+ super(date);
63
+ if (!isNaN(this.getTime())) {
64
+ this.#hasDate = hasDate;
65
+ this.#hasTime = hasTime;
66
+ this.#offset = offset;
67
+ }
68
+ }
69
+ isDateTime() {
70
+ return this.#hasDate && this.#hasTime;
71
+ }
72
+ isLocal() {
73
+ return !this.#hasDate || !this.#hasTime || !this.#offset;
74
+ }
75
+ isDate() {
76
+ return this.#hasDate && !this.#hasTime;
77
+ }
78
+ isTime() {
79
+ return this.#hasTime && !this.#hasDate;
80
+ }
81
+ isValid() {
82
+ return this.#hasDate || this.#hasTime;
83
+ }
84
+ toISOString() {
85
+ let iso = super.toISOString();
86
+ // Local Date
87
+ if (this.isDate())
88
+ return iso.slice(0, 10);
89
+ // Local Time
90
+ if (this.isTime())
91
+ return iso.slice(11, 23);
92
+ // Local DateTime
93
+ if (this.#offset === null)
94
+ return iso.slice(0, -1);
95
+ // Offset DateTime
96
+ if (this.#offset === 'Z')
97
+ return iso;
98
+ // This part is quite annoying: JS strips the original timezone from the ISO string representation
99
+ // Instead of using a "modified" date and "Z", we restore the representation "as authored"
100
+ let offset = (+(this.#offset.slice(1, 3)) * 60) + +(this.#offset.slice(4, 6));
101
+ offset = this.#offset[0] === '-' ? offset : -offset;
102
+ let offsetDate = new Date(this.getTime() - (offset * 60e3));
103
+ return offsetDate.toISOString().slice(0, -1) + this.#offset;
104
+ }
105
+ static wrapAsOffsetDateTime(jsDate, offset = 'Z') {
106
+ let date = new TomlDate(jsDate);
107
+ date.#offset = offset;
108
+ return date;
109
+ }
110
+ static wrapAsLocalDateTime(jsDate) {
111
+ let date = new TomlDate(jsDate);
112
+ date.#offset = null;
113
+ return date;
114
+ }
115
+ static wrapAsLocalDate(jsDate) {
116
+ let date = new TomlDate(jsDate);
117
+ date.#hasTime = false;
118
+ date.#offset = null;
119
+ return date;
120
+ }
121
+ static wrapAsLocalTime(jsDate) {
122
+ let date = new TomlDate(jsDate);
123
+ date.#hasDate = false;
124
+ date.#offset = null;
125
+ return date;
126
+ }
127
+ }
@@ -0,0 +1,63 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ function getLineColFromPtr(string, ptr) {
29
+ let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g);
30
+ return [lines.length, lines.pop().length + 1];
31
+ }
32
+ function makeCodeBlock(string, line, column) {
33
+ let lines = string.split(/\r\n|\n|\r/g);
34
+ let codeblock = '';
35
+ let numberLen = (Math.log10(line + 1) | 0) + 1;
36
+ for (let i = line - 1; i <= line + 1; i++) {
37
+ let l = lines[i - 1];
38
+ if (!l)
39
+ continue;
40
+ codeblock += i.toString().padEnd(numberLen, ' ');
41
+ codeblock += ': ';
42
+ codeblock += l;
43
+ codeblock += '\n';
44
+ if (i === line) {
45
+ codeblock += ' '.repeat(numberLen + column + 2);
46
+ codeblock += '^\n';
47
+ }
48
+ }
49
+ return codeblock;
50
+ }
51
+ export class TomlError extends Error {
52
+ line;
53
+ column;
54
+ codeblock;
55
+ constructor(message, options) {
56
+ const [line, column] = getLineColFromPtr(options.toml, options.ptr);
57
+ const codeblock = makeCodeBlock(options.toml, line, column);
58
+ super(`Invalid TOML document: ${message}\n\n${codeblock}`, options);
59
+ this.line = line;
60
+ this.column = column;
61
+ this.codeblock = codeblock;
62
+ }
63
+ }
@@ -0,0 +1,100 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ import { parseString, parseValue } from './primitive.js';
29
+ import { parseArray, parseInlineTable } from './struct.js';
30
+ import { skipVoid, skipUntil, skipComment, getStringEnd } from './util.js';
31
+ import { TomlError } from './error.js';
32
+ function sliceAndTrimEndOf(str, startPtr, endPtr) {
33
+ let value = str.slice(startPtr, endPtr);
34
+ let commentIdx = value.indexOf('#');
35
+ if (commentIdx > -1) {
36
+ // The call to skipComment allows to "validate" the comment
37
+ // (absence of control characters)
38
+ skipComment(str, commentIdx);
39
+ value = value.slice(0, commentIdx);
40
+ }
41
+ return [value.trimEnd(), commentIdx];
42
+ }
43
+ export function extractValue(str, ptr, end, depth, integersAsBigInt) {
44
+ if (depth === 0) {
45
+ throw new TomlError('document contains excessively nested structures. aborting.', {
46
+ toml: str,
47
+ ptr: ptr
48
+ });
49
+ }
50
+ let c = str[ptr];
51
+ if (c === '[' || c === '{') {
52
+ let [value, endPtr] = c === '['
53
+ ? parseArray(str, ptr, depth, integersAsBigInt)
54
+ : parseInlineTable(str, ptr, depth, integersAsBigInt);
55
+ if (end) {
56
+ endPtr = skipVoid(str, endPtr);
57
+ if (str[endPtr] === ',')
58
+ endPtr++;
59
+ else if (str[endPtr] !== end) {
60
+ throw new TomlError('expected comma or end of structure', {
61
+ toml: str,
62
+ ptr: endPtr,
63
+ });
64
+ }
65
+ }
66
+ return [value, endPtr];
67
+ }
68
+ let endPtr;
69
+ if (c === '"' || c === "'") {
70
+ endPtr = getStringEnd(str, ptr);
71
+ let parsed = parseString(str, ptr, endPtr);
72
+ if (end) {
73
+ endPtr = skipVoid(str, endPtr);
74
+ if (str[endPtr] && str[endPtr] !== ',' && str[endPtr] !== end && str[endPtr] !== '\n' && str[endPtr] !== '\r') {
75
+ throw new TomlError('unexpected character encountered', {
76
+ toml: str,
77
+ ptr: endPtr,
78
+ });
79
+ }
80
+ endPtr += (+(str[endPtr] === ','));
81
+ }
82
+ return [parsed, endPtr];
83
+ }
84
+ endPtr = skipUntil(str, ptr, ',', end);
85
+ let slice = sliceAndTrimEndOf(str, ptr, endPtr - (+(str[endPtr - 1] === ',')));
86
+ if (!slice[0]) {
87
+ throw new TomlError('incomplete key-value declaration: no value specified', {
88
+ toml: str,
89
+ ptr: ptr
90
+ });
91
+ }
92
+ if (end && slice[1] > -1) {
93
+ endPtr = skipVoid(str, ptr + slice[1]);
94
+ endPtr += +(str[endPtr] === ',');
95
+ }
96
+ return [
97
+ parseValue(slice[0], str, ptr, integersAsBigInt),
98
+ endPtr,
99
+ ];
100
+ }
@@ -0,0 +1,148 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ import { parseKey } from './struct.js';
29
+ import { extractValue } from './extract.js';
30
+ import { skipVoid } from './util.js';
31
+ import { TomlError } from './error.js';
32
+ function peekTable(key, table, meta, type) {
33
+ let t = table;
34
+ let m = meta;
35
+ let k;
36
+ let hasOwn = false;
37
+ let state;
38
+ for (let i = 0; i < key.length; i++) {
39
+ if (i) {
40
+ t = hasOwn ? t[k] : (t[k] = {});
41
+ m = (state = m[k]).c;
42
+ if (type === 0 /* Type.DOTTED */ && (state.t === 1 /* Type.EXPLICIT */ || state.t === 2 /* Type.ARRAY */)) {
43
+ return null;
44
+ }
45
+ if (state.t === 2 /* Type.ARRAY */) {
46
+ let l = t.length - 1;
47
+ t = t[l];
48
+ m = m[l].c;
49
+ }
50
+ }
51
+ k = key[i];
52
+ if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 /* Type.DOTTED */ && m[k]?.d) {
53
+ return null;
54
+ }
55
+ if (!hasOwn) {
56
+ if (k === '__proto__') {
57
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
58
+ Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
59
+ }
60
+ m[k] = {
61
+ t: i < key.length - 1 && type === 2 /* Type.ARRAY */
62
+ ? 3 /* Type.ARRAY_DOTTED */
63
+ : type,
64
+ d: false,
65
+ i: 0,
66
+ c: {},
67
+ };
68
+ }
69
+ }
70
+ state = m[k];
71
+ if (state.t !== type && !(type === 1 /* Type.EXPLICIT */ && state.t === 3 /* Type.ARRAY_DOTTED */)) {
72
+ // Bad key type!
73
+ return null;
74
+ }
75
+ if (type === 2 /* Type.ARRAY */) {
76
+ if (!state.d) {
77
+ state.d = true;
78
+ t[k] = [];
79
+ }
80
+ t[k].push(t = {});
81
+ state.c[state.i++] = (state = { t: 1 /* Type.EXPLICIT */, d: false, i: 0, c: {} });
82
+ }
83
+ if (state.d) {
84
+ // Redefining a table!
85
+ return null;
86
+ }
87
+ state.d = true;
88
+ if (type === 1 /* Type.EXPLICIT */) {
89
+ t = hasOwn ? t[k] : (t[k] = {});
90
+ }
91
+ else if (type === 0 /* Type.DOTTED */ && hasOwn) {
92
+ return null;
93
+ }
94
+ return [k, t, state.c];
95
+ }
96
+ export function parse(toml, { maxDepth = 1000, integersAsBigInt } = {}) {
97
+ let res = {};
98
+ let meta = {};
99
+ let tbl = res;
100
+ let m = meta;
101
+ for (let ptr = skipVoid(toml, 0); ptr < toml.length;) {
102
+ if (toml[ptr] === '[') {
103
+ let isTableArray = toml[++ptr] === '[';
104
+ let k = parseKey(toml, ptr += +isTableArray, ']');
105
+ if (isTableArray) {
106
+ if (toml[k[1] - 1] !== ']') {
107
+ throw new TomlError('expected end of table declaration', {
108
+ toml: toml,
109
+ ptr: k[1] - 1,
110
+ });
111
+ }
112
+ k[1]++;
113
+ }
114
+ let p = peekTable(k[0], res, meta, isTableArray ? 2 /* Type.ARRAY */ : 1 /* Type.EXPLICIT */);
115
+ if (!p) {
116
+ throw new TomlError('trying to redefine an already defined table or value', {
117
+ toml: toml,
118
+ ptr: ptr,
119
+ });
120
+ }
121
+ m = p[2];
122
+ tbl = p[1];
123
+ ptr = k[1];
124
+ }
125
+ else {
126
+ let k = parseKey(toml, ptr);
127
+ let p = peekTable(k[0], tbl, m, 0 /* Type.DOTTED */);
128
+ if (!p) {
129
+ throw new TomlError('trying to redefine an already defined table or value', {
130
+ toml: toml,
131
+ ptr: ptr,
132
+ });
133
+ }
134
+ let v = extractValue(toml, k[1], void 0, maxDepth, integersAsBigInt);
135
+ p[1][p[0]] = v[0];
136
+ ptr = v[1];
137
+ }
138
+ ptr = skipVoid(toml, ptr, true);
139
+ if (toml[ptr] && toml[ptr] !== '\n' && toml[ptr] !== '\r') {
140
+ throw new TomlError('each key-value declaration must be followed by an end-of-line', {
141
+ toml: toml,
142
+ ptr: ptr
143
+ });
144
+ }
145
+ ptr = skipVoid(toml, ptr);
146
+ }
147
+ return res;
148
+ }