kimi-plugin-cc 2.4.4 → 2.5.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.
Files changed (119) 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 +50 -34
  5. package/dist/commands/swarm.js +1 -1
  6. package/dist/dsh/companion.js +174 -0
  7. package/dist/dsh/index.js +156 -0
  8. package/dist/hooks/config-safety.js +3 -2
  9. package/dist/hooks/install-paths.js +2 -2
  10. package/dist/kimi-engine.js +1 -0
  11. package/dist/swarm-activation.js +1 -1
  12. package/dist/version.js +1 -1
  13. package/docs/migration.md +4 -4
  14. package/docs/models.md +5 -1
  15. package/docs/registry-releases.md +20 -17
  16. package/docs/safety.md +28 -15
  17. package/docs/swarm-recovery.md +1 -1
  18. package/docs/upstream-2.4.1-certification.md +54 -0
  19. package/package.json +41 -6
  20. package/plugins/kimi-codex/.codex-plugin/plugin.json +1 -1
  21. package/plugins/kimi-codex/dist/commands/swarm.js +1 -1
  22. package/plugins/kimi-codex/dist/dsh/companion.js +174 -0
  23. package/plugins/kimi-codex/dist/dsh/index.js +156 -0
  24. package/plugins/kimi-codex/dist/hooks/config-safety.js +3 -2
  25. package/plugins/kimi-codex/dist/hooks/install-paths.js +2 -2
  26. package/plugins/kimi-codex/dist/kimi-engine.js +1 -0
  27. package/plugins/kimi-codex/dist/swarm-activation.js +1 -1
  28. package/plugins/kimi-codex/dist/version.js +1 -1
  29. package/plugins/kimi-dsh/LICENSE +201 -0
  30. package/plugins/kimi-dsh/README.md +80 -0
  31. package/plugins/kimi-dsh/cordis.patch.yml +45 -0
  32. package/plugins/kimi-dsh/dist/background-spawn.js +216 -0
  33. package/plugins/kimi-dsh/dist/cli-cancellation.js +43 -0
  34. package/plugins/kimi-dsh/dist/cli-client.js +876 -0
  35. package/plugins/kimi-dsh/dist/commands/ask.js +336 -0
  36. package/plugins/kimi-dsh/dist/commands/cancel.js +216 -0
  37. package/plugins/kimi-dsh/dist/commands/cli-helpers.js +201 -0
  38. package/plugins/kimi-dsh/dist/commands/models.js +140 -0
  39. package/plugins/kimi-dsh/dist/commands/not-implemented.js +4 -0
  40. package/plugins/kimi-dsh/dist/commands/pursue.js +307 -0
  41. package/plugins/kimi-dsh/dist/commands/recover-swarm.js +135 -0
  42. package/plugins/kimi-dsh/dist/commands/registry.js +74 -0
  43. package/plugins/kimi-dsh/dist/commands/repair-sessions.js +160 -0
  44. package/plugins/kimi-dsh/dist/commands/replay.js +124 -0
  45. package/plugins/kimi-dsh/dist/commands/rescue.js +347 -0
  46. package/plugins/kimi-dsh/dist/commands/result.js +66 -0
  47. package/plugins/kimi-dsh/dist/commands/review-gate.js +390 -0
  48. package/plugins/kimi-dsh/dist/commands/review.js +220 -0
  49. package/plugins/kimi-dsh/dist/commands/setup.js +1047 -0
  50. package/plugins/kimi-dsh/dist/commands/status.js +27 -0
  51. package/plugins/kimi-dsh/dist/commands/swarm.js +754 -0
  52. package/plugins/kimi-dsh/dist/commands/worker.js +25 -0
  53. package/plugins/kimi-dsh/dist/companion.js +97 -0
  54. package/plugins/kimi-dsh/dist/config.js +22 -0
  55. package/plugins/kimi-dsh/dist/dsh/companion.js +174 -0
  56. package/plugins/kimi-dsh/dist/dsh/index.js +156 -0
  57. package/plugins/kimi-dsh/dist/errors.js +40 -0
  58. package/plugins/kimi-dsh/dist/git.js +224 -0
  59. package/plugins/kimi-dsh/dist/help.js +43 -0
  60. package/plugins/kimi-dsh/dist/hook-escape.js +71 -0
  61. package/plugins/kimi-dsh/dist/hooks/approval-hook.js +101 -0
  62. package/plugins/kimi-dsh/dist/hooks/approval-policy.js +211 -0
  63. package/plugins/kimi-dsh/dist/hooks/config-safety.js +653 -0
  64. package/plugins/kimi-dsh/dist/hooks/install-paths.js +428 -0
  65. package/plugins/kimi-dsh/dist/hooks/install.js +210 -0
  66. package/plugins/kimi-dsh/dist/hooks/managed-block.js +619 -0
  67. package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +19 -0
  68. package/plugins/kimi-dsh/dist/job-id.js +12 -0
  69. package/plugins/kimi-dsh/dist/job-store.js +659 -0
  70. package/plugins/kimi-dsh/dist/jobs.js +217 -0
  71. package/plugins/kimi-dsh/dist/kimi-command.js +70 -0
  72. package/plugins/kimi-dsh/dist/kimi-engine.js +632 -0
  73. package/plugins/kimi-dsh/dist/kimi-errors.js +260 -0
  74. package/plugins/kimi-dsh/dist/kimi-home.js +9 -0
  75. package/plugins/kimi-dsh/dist/kimi-timeouts.js +52 -0
  76. package/plugins/kimi-dsh/dist/kimi-version-probe.js +216 -0
  77. package/plugins/kimi-dsh/dist/logging.js +22 -0
  78. package/plugins/kimi-dsh/dist/mcp/binding.js +58 -0
  79. package/plugins/kimi-dsh/dist/mcp/job-control.js +345 -0
  80. package/plugins/kimi-dsh/dist/mcp/launcher.js +257 -0
  81. package/plugins/kimi-dsh/dist/mcp/operations.js +301 -0
  82. package/plugins/kimi-dsh/dist/mcp/protocol.js +275 -0
  83. package/plugins/kimi-dsh/dist/mcp/server.js +8 -0
  84. package/plugins/kimi-dsh/dist/mcp/stdio.js +78 -0
  85. package/plugins/kimi-dsh/dist/mcp/supervised-child.js +15 -0
  86. package/plugins/kimi-dsh/dist/mcp/tool-result.js +7 -0
  87. package/plugins/kimi-dsh/dist/mcp/workspace.js +34 -0
  88. package/plugins/kimi-dsh/dist/model-command.js +32 -0
  89. package/plugins/kimi-dsh/dist/native-v2-preflight.js +417 -0
  90. package/plugins/kimi-dsh/dist/package.json +1 -0
  91. package/plugins/kimi-dsh/dist/parsing.js +620 -0
  92. package/plugins/kimi-dsh/dist/paths.js +27 -0
  93. package/plugins/kimi-dsh/dist/plugin-data.js +98 -0
  94. package/plugins/kimi-dsh/dist/process-tree.js +479 -0
  95. package/plugins/kimi-dsh/dist/prompt-size.js +18 -0
  96. package/plugins/kimi-dsh/dist/render.js +177 -0
  97. package/plugins/kimi-dsh/dist/rescue-approval.js +865 -0
  98. package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +43 -0
  99. package/plugins/kimi-dsh/dist/session-recovery.js +200 -0
  100. package/plugins/kimi-dsh/dist/session-title.js +293 -0
  101. package/plugins/kimi-dsh/dist/stream-json.js +346 -0
  102. package/plugins/kimi-dsh/dist/swarm-activation.js +834 -0
  103. package/plugins/kimi-dsh/dist/swarm-recovery.js +134 -0
  104. package/plugins/kimi-dsh/dist/types.js +1 -0
  105. package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +24 -0
  106. package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +1 -0
  107. package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +229 -0
  108. package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +24 -0
  109. package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +156 -0
  110. package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +67 -0
  111. package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +293 -0
  112. package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +164 -0
  113. package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +151 -0
  114. package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +156 -0
  115. package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +57 -0
  116. package/plugins/kimi-dsh/dist/version.js +7 -0
  117. package/plugins/kimi-dsh/package.json +48 -0
  118. package/plugins/kimi-dsh/scripts/companion.sh +37 -0
  119. package/plugins/kimi-dsh/scripts/review-gate-hook.sh +32 -0
@@ -0,0 +1,134 @@
1
+ import { RuntimeError } from "./errors.js";
2
+ import { collectDescendantIdentities, collectProcessGroupsIdentities, probeProcessIdentity, revalidateProcessIdentities } from "./process-tree.js";
3
+ export function recordRecoveryEvent(store, record, event) {
4
+ record.complete = false;
5
+ if (event.kind === "session") {
6
+ record.session = { sessionId: event.sessionId, workspaceId: event.workspaceId };
7
+ // Write-ahead: this must commit before the profile mutation is attempted.
8
+ record.sessionDirty = true;
9
+ }
10
+ else if (event.kind === "disabled") {
11
+ record.sessionDirty = false;
12
+ }
13
+ else if (event.kind.endsWith("-spawn")) {
14
+ record.launches.push({ kind: event.kind === "web-spawn" ? "web" : "print", pending: true, identities: [], quiescent: false, uncertain: false });
15
+ }
16
+ else {
17
+ const kind = event.kind.startsWith("web-") ? "web" : "print";
18
+ const launch = [...record.launches].reverse().find((entry) => entry.kind === kind);
19
+ if (!launch)
20
+ throw recoveryError("Missing durable launch intent.");
21
+ if (event.kind === "web-exit" || event.kind === "print-exit") {
22
+ launch.quiescent = true;
23
+ launch.pending = false;
24
+ }
25
+ else if ("identities" in event) {
26
+ const all = [...launch.identities, ...event.identities];
27
+ launch.identities = [...new Map(all.map((identity) => [`${identity.pid}:${identity.startToken}:${identity.processGroupId}`, identity])).values()];
28
+ launch.pending = launch.identities.length === 0;
29
+ launch.uncertain ||= !event.complete;
30
+ }
31
+ }
32
+ store.saveSwarmRecovery(record.jobId, record);
33
+ }
34
+ export function finishRecoveryRecord(store, record) {
35
+ record.complete = !record.sessionDirty && record.launches.every((entry) => entry.quiescent)
36
+ && (record.workspaceRoot === null || record.patchPath !== null);
37
+ store.saveSwarmRecovery(record.jobId, record);
38
+ }
39
+ export function recoveryError(message) {
40
+ return new RuntimeError("SWARM_RECOVERY_REQUIRED", message, "swarm.recovery");
41
+ }
42
+ export async function assertRecoveryOwnerGone(record) {
43
+ if (!record.owner || process.platform === "win32")
44
+ throw recoveryError("No durable, verifiable owner identity; recovery requires manual inspection on this host.");
45
+ const probe = await probeProcessIdentity(record.ownerPid);
46
+ if (!probe.complete)
47
+ throw recoveryError("Cannot verify the original companion's identity.");
48
+ if (probe.identity?.startToken === record.owner.startToken && !/^[ZX]/i.test(probe.identity.state)) {
49
+ throw recoveryError("The original companion is still alive. Use cancel for a running job, not recovery.");
50
+ }
51
+ }
52
+ /**
53
+ * Linux may fall back from /proc to ps for a whole-group snapshot while targeted
54
+ * identity reads still use /proc. Those start tokens are different namespaces,
55
+ * not different processes. Prove both representations current around the known
56
+ * identity read; never accept a member based on PID/PGID equality alone.
57
+ */
58
+ export async function validateRecoveryGroupMembers(known, members, validate = revalidateProcessIdentities) {
59
+ const membership = await validate(members);
60
+ const ownership = await validate(known);
61
+ const membershipAfter = await validate(membership.identities);
62
+ for (const proof of [membership, ownership, membershipAfter]) {
63
+ if (!proof.complete || proof.groupChanged?.length)
64
+ throw recoveryError("Process ownership or group membership is uncertain.");
65
+ }
66
+ for (const member of membershipAfter.identities) {
67
+ const owner = ownership.identities.find((id) => id.pid === member.pid && id.processGroupId === member.processGroupId);
68
+ const crossNamespace = owner && ((owner.startToken.startsWith("proc:") && member.startToken.startsWith("ps:")) ||
69
+ (owner.startToken.startsWith("ps:") && member.startToken.startsWith("proc:")));
70
+ if (!owner || (owner.startToken !== member.startToken && !crossNamespace)) {
71
+ throw recoveryError("An unrecorded process survives in the recorded group; refusing group cleanup.");
72
+ }
73
+ }
74
+ return ownership.identities;
75
+ }
76
+ /** Never signal an unproven group, PID replacement, or changed-PGID process. */
77
+ export async function recoverLaunch(launch, persist, signal) {
78
+ if (launch.quiescent)
79
+ return;
80
+ if (launch.pending || launch.uncertain || launch.identities.length === 0) {
81
+ throw recoveryError("Launch ownership was not fully recorded before interruption; manual inspection is required. No process was signalled.");
82
+ }
83
+ const root = launch.identities[0];
84
+ const rootProbe = await probeProcessIdentity(root.pid);
85
+ if (!rootProbe.complete)
86
+ throw recoveryError("Process identity probe is incomplete.");
87
+ if (rootProbe.identity?.startToken === root.startToken) {
88
+ if (rootProbe.identity.processGroupId !== root.processGroupId)
89
+ throw recoveryError("The recorded root changed process groups; refusing to signal it.");
90
+ const descendants = await collectDescendantIdentities(root.pid);
91
+ // Revalidate the ancestry anchor after collection before retaining new identities.
92
+ const after = await probeProcessIdentity(root.pid);
93
+ if (!after.complete || after.identity?.startToken !== root.startToken || after.identity.processGroupId !== root.processGroupId) {
94
+ throw recoveryError("Process ownership changed during recovery inspection.");
95
+ }
96
+ launch.identities = [...new Map([...launch.identities, ...descendants].map((id) => [`${id.pid}:${id.startToken}:${id.processGroupId}`, id])).values()];
97
+ persist();
98
+ }
99
+ const inspect = async () => {
100
+ const members = await collectProcessGroupsIdentities(launch.identities.map((id) => id.processGroupId));
101
+ if (members === undefined)
102
+ throw recoveryError("Process group membership is unreadable.");
103
+ return validateRecoveryGroupMembers(launch.identities, members);
104
+ };
105
+ for (const [killSignal, waitMs] of [["SIGTERM", 1500], ["SIGKILL", 500]]) {
106
+ signal?.throwIfAborted();
107
+ for (const identity of await inspect()) {
108
+ signal?.throwIfAborted();
109
+ const current = await revalidateProcessIdentities([identity]);
110
+ if (!current.complete || current.groupChanged?.length)
111
+ throw recoveryError("Process identity changed before signalling.");
112
+ if (current.identities.length) {
113
+ try {
114
+ process.kill(identity.pid, killSignal);
115
+ }
116
+ catch (error) {
117
+ if (error.code !== "ESRCH")
118
+ throw recoveryError("Unable to stop the recorded process.");
119
+ }
120
+ }
121
+ }
122
+ const deadline = Date.now() + waitMs;
123
+ do {
124
+ signal?.throwIfAborted();
125
+ if ((await inspect()).length === 0) {
126
+ launch.quiescent = true;
127
+ persist();
128
+ return;
129
+ }
130
+ await new Promise((resolve) => setTimeout(resolve, 25));
131
+ } while (Date.now() < deadline);
132
+ }
133
+ throw recoveryError("Recorded processes did not become quiescent; recovery remains pending.");
134
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2013 James Halliday (mail@substack.net)
4
+
5
+ Permission is hereby granted, free of charge,
6
+ to any person obtaining a copy of this software and
7
+ associated documentation files (the "Software"), to
8
+ deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify,
10
+ merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom
12
+ the Software is furnished to do so,
13
+ subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice
16
+ shall be included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
22
+ ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ export { parse } from "./parse.js";
@@ -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,156 @@
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})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
29
+ export class TomlDate extends Date {
30
+ #hasDate = false;
31
+ #hasTime = false;
32
+ #offset = null;
33
+ constructor(date, fasttype, unsafeDelim) {
34
+ let hasDate = true;
35
+ let hasTime = true;
36
+ let offset = 'Z';
37
+ let c;
38
+ if (typeof date === 'string') {
39
+ if (fasttype)
40
+ prep: {
41
+ // Date-time
42
+ if (fasttype < 3) {
43
+ if (+date.slice(11, 13) > 23) {
44
+ date = '';
45
+ break prep;
46
+ }
47
+ // Local
48
+ if (fasttype === 2) {
49
+ offset = null;
50
+ date += 'Z';
51
+ }
52
+ // Offset; keep track of offset if not Z
53
+ else if ((c = date.charCodeAt(date.length - 1)) !== 0x5a /* Z */ && c !== 0x7a /* z */) {
54
+ offset = date.slice(date.length - 6);
55
+ }
56
+ if (unsafeDelim)
57
+ date = date.slice(0, 10) + 'T' + date.slice(11);
58
+ }
59
+ // Time
60
+ else if (fasttype === 4) {
61
+ date = +date.slice(0, 2) > 23 ? '' : `0000-01-01T${date}Z`;
62
+ }
63
+ hasDate = fasttype !== 4;
64
+ hasTime = fasttype !== 3;
65
+ }
66
+ else {
67
+ let match = date.match(DATE_TIME_RE);
68
+ if (match) {
69
+ if (!match[1]) {
70
+ hasDate = false;
71
+ date = `0000-01-01T${date}`;
72
+ }
73
+ hasTime = !!match[2];
74
+ // Make sure to use T instead of a space. Breaks in case of extreme values otherwise.
75
+ hasTime && date[10] === ' ' && (date = date.replace(' ', 'T'));
76
+ // Do not allow rollover hours.
77
+ if (match[2] && +match[2] > 23) {
78
+ date = '';
79
+ }
80
+ else {
81
+ offset = match[3] || null;
82
+ if (!offset && hasTime)
83
+ date += 'Z';
84
+ }
85
+ }
86
+ else {
87
+ date = '';
88
+ }
89
+ }
90
+ }
91
+ super(date);
92
+ if (!isNaN(this.getTime())) {
93
+ this.#hasDate = hasDate;
94
+ this.#hasTime = hasTime;
95
+ this.#offset = offset;
96
+ }
97
+ }
98
+ isDateTime() {
99
+ return this.#hasDate && this.#hasTime;
100
+ }
101
+ isLocal() {
102
+ return !this.#hasDate || !this.#hasTime || !this.#offset;
103
+ }
104
+ isDate() {
105
+ return this.#hasDate && !this.#hasTime;
106
+ }
107
+ isTime() {
108
+ return this.#hasTime && !this.#hasDate;
109
+ }
110
+ isValid() {
111
+ return this.#hasDate || this.#hasTime;
112
+ }
113
+ toISOString() {
114
+ let iso = super.toISOString();
115
+ // Local Date
116
+ if (this.isDate())
117
+ return iso.slice(0, 10);
118
+ // Local Time
119
+ if (this.isTime())
120
+ return iso.slice(11, 23);
121
+ // Local DateTime
122
+ if (this.#offset === null)
123
+ return iso.slice(0, -1);
124
+ // Offset DateTime
125
+ if (this.#offset === 'Z' || this.#offset === 'z')
126
+ return iso;
127
+ // This part is quite annoying: JS strips the original timezone from the ISO string representation
128
+ // Instead of using a "modified" date and "Z", we restore the representation "as authored"
129
+ let offset = (+(this.#offset.slice(1, 3)) * 60) + +(this.#offset.slice(4, 6));
130
+ offset = this.#offset[0] === '-' ? offset : -offset;
131
+ let offsetDate = new Date(this.getTime() - (offset * 60e3));
132
+ return offsetDate.toISOString().slice(0, -1) + this.#offset;
133
+ }
134
+ static wrapAsOffsetDateTime(jsDate, offset = 'Z') {
135
+ let date = new TomlDate(jsDate);
136
+ date.#offset = offset;
137
+ return date;
138
+ }
139
+ static wrapAsLocalDateTime(jsDate) {
140
+ let date = new TomlDate(jsDate);
141
+ date.#offset = null;
142
+ return date;
143
+ }
144
+ static wrapAsLocalDate(jsDate) {
145
+ let date = new TomlDate(jsDate);
146
+ date.#hasTime = false;
147
+ date.#offset = null;
148
+ return date;
149
+ }
150
+ static wrapAsLocalTime(jsDate) {
151
+ let date = new TomlDate(jsDate);
152
+ date.#hasDate = false;
153
+ date.#offset = null;
154
+ return date;
155
+ }
156
+ }
@@ -0,0 +1,67 @@
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/);
30
+ return [lines.length, lines.pop().length + 1];
31
+ }
32
+ function makeCodeBlock(string, line, column) {
33
+ let lines = string.split(/\r?\n/);
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
+ /** @internal */
64
+ static x(message, ctx, ptr) {
65
+ throw new TomlError(message, { toml: ctx.s, ptr: ptr ?? ctx.p });
66
+ }
67
+ }