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
@@ -11,8 +11,11 @@ export class JobStore {
11
11
  let db;
12
12
  try {
13
13
  db = createSqliteAdapter(paths.stateDbPath);
14
- db.pragma("journal_mode = WAL");
14
+ // busy_timeout FIRST: switching the journal mode takes a brief write lock,
15
+ // and a second opener (status/result racing a worker) otherwise fails
16
+ // immediately with SQLITE_BUSY instead of waiting (seen 2026-10-14).
15
17
  db.pragma("busy_timeout = 5000");
18
+ db.pragma("journal_mode = WAL");
16
19
  }
17
20
  catch (error) {
18
21
  try {
@@ -70,6 +73,11 @@ export class JobStore {
70
73
  if (!tableHasColumn(this.db, "budget_ms")) {
71
74
  this.db.exec(`ALTER TABLE jobs ADD COLUMN budget_ms INTEGER;`);
72
75
  }
76
+ for (const column of ["kimi_session_id_source", "budget_source"]) {
77
+ if (!tableHasColumn(this.db, column)) {
78
+ this.db.exec("ALTER TABLE jobs ADD COLUMN " + column + " TEXT;");
79
+ }
80
+ }
73
81
  // Additive provenance migration. Existing rows deliberately remain NULL:
74
82
  // v1.9.5 plus kimi-code 0.33/0.34 could have routed to native v2 before the
75
83
  // legacy pin landed, so a blanket historical v1 backfill would invent fact.
@@ -98,6 +106,8 @@ export class JobStore {
98
106
  CREATE INDEX IF NOT EXISTS jobs_repo_type_updated_idx
99
107
  ON jobs (repo_id, command_type, updated_at DESC);
100
108
 
109
+ CREATE INDEX IF NOT EXISTS jobs_session_id_idx ON jobs (kimi_session_id);
110
+
101
111
  CREATE INDEX IF NOT EXISTS jobs_session_idx
102
112
  ON jobs (repo_id, kimi_session_id, updated_at DESC);
103
113
 
@@ -163,14 +173,14 @@ export class JobStore {
163
173
  this.db.run(`
164
174
  INSERT INTO jobs (
165
175
  job_id, repo_id, command_type, created_at, updated_at, cwd, model, thinking,
166
- background, pid, kimi_pid, status, kimi_session_id,
176
+ background, pid, kimi_pid, status, kimi_session_id, kimi_session_id_source, budget_source,
167
177
  operation_kind, intended_engine, observed_engine, kimi_version, system_version,
168
178
  kimi_command, kimi_prefix_args, plan_certification, resumed_from_job_id, safety_profile,
169
179
  agent_profile, prompt_digest, summary, phase, budget_ms, final_output_path, stream_log_path, error
170
180
  )
171
181
  VALUES (
172
182
  @job_id, @repo_id, @command_type, @created_at, @updated_at, @cwd, @model, @thinking,
173
- @background, @pid, @kimi_pid, @status, @kimi_session_id,
183
+ @background, @pid, @kimi_pid, @status, @kimi_session_id, @kimi_session_id_source, @budget_source,
174
184
  @operation_kind, @intended_engine, @observed_engine, @kimi_version, @system_version,
175
185
  @kimi_command, @kimi_prefix_args, @plan_certification, @resumed_from_job_id, @safety_profile,
176
186
  @agent_profile, @prompt_digest, @summary, @phase, @budget_ms, @final_output_path, @stream_log_path, @error
@@ -198,6 +208,10 @@ export class JobStore {
198
208
  const row = this.db.get("SELECT * FROM jobs WHERE job_id = ?", jobId);
199
209
  return row ? hydrateRow(row) : null;
200
210
  }
211
+ /** Global across repos and terminal states; optionally exclude the current row. */
212
+ hasSessionId(sessionId, exceptJobId = "") {
213
+ return Boolean(this.db.get("SELECT 1 FROM jobs WHERE kimi_session_id = ? AND job_id != ? LIMIT 1", sessionId, exceptJobId));
214
+ }
201
215
  findLatestJob(options) {
202
216
  const conditions = ["repo_id = @repo_id"];
203
217
  const params = {
@@ -247,6 +261,18 @@ export class JobStore {
247
261
  updateRunningJob(jobId, patch) {
248
262
  return this.updateWhere(jobId, patch, "status = 'running'");
249
263
  }
264
+ /** Recheck uniqueness atomically: another worker can claim an ID during the
265
+ * asynchronous directory scan. Ordinary announced/resumed IDs may be shared. */
266
+ claimRecoveredSessionId(jobId, sessionId) {
267
+ this.db.run(`UPDATE jobs
268
+ SET kimi_session_id = @session_id, kimi_session_id_source = 'recovered_session_dir',
269
+ updated_at = @updated_at
270
+ WHERE job_id = @job_id AND status = 'running' AND kimi_session_id IS NULL
271
+ AND NOT EXISTS (SELECT 1 FROM jobs WHERE kimi_session_id = @session_id AND job_id != @job_id)`, { job_id: jobId, session_id: sessionId, updated_at: new Date().toISOString() });
272
+ const job = this.getJob(jobId);
273
+ return job?.status === "running" && job.kimi_session_id === sessionId &&
274
+ job.kimi_session_id_source === "recovered_session_dir" ? job : null;
275
+ }
250
276
  /**
251
277
  * Evidence-only backfill for pre-provenance rows. COALESCE prevents forensic
252
278
  * inspection from overwriting a field already recorded at execution time.
@@ -280,7 +306,7 @@ export class JobStore {
280
306
  return this.updateWhere(jobId, { ...patch, status: "cancelled", pid: null, kimi_pid: null }, "status = 'running'");
281
307
  }
282
308
  static JOBS_COLUMNS = new Set([
283
- "status", "summary", "phase", "budget_ms", "pid", "kimi_pid",
309
+ "status", "summary", "phase", "budget_ms", "budget_source", "kimi_session_id_source", "pid", "kimi_pid",
284
310
  "final_output_path", "stream_log_path", "kimi_session_id",
285
311
  "error", "command_type", "prompt_digest", "repo_id",
286
312
  "cwd", "model", "thinking", "background", "agent_profile",
@@ -325,6 +351,8 @@ function serializeRecord(record) {
325
351
  ...record,
326
352
  phase: record.phase ?? null,
327
353
  budget_ms: record.budget_ms ?? null,
354
+ budget_source: record.budget_source ?? null,
355
+ kimi_session_id_source: record.kimi_session_id_source ?? null,
328
356
  operation_kind: record.operation_kind ?? null,
329
357
  intended_engine: record.intended_engine ?? null,
330
358
  observed_engine: record.observed_engine ?? null,
@@ -562,3 +590,7 @@ export function withJobStoreSync(paths, fn) {
562
590
  store?.close();
563
591
  }
564
592
  }
593
+ /** Old non-null budgets have unknown provenance; never invent explicit intent. */
594
+ export function renderBudgetSource(job) {
595
+ return job.budget_source ?? (job.budget_ms === null ? "default" : "unknown");
596
+ }
@@ -0,0 +1,203 @@
1
+ import { constants } from "node:fs";
2
+ import { lstat, open, opendir, realpath } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { digestPrompt } from "./jobs.js";
5
+ // Total entries visited across both enumeration levels. A real store holds a
6
+ // few thousand sessions (2,494 entries on the reference host when this was
7
+ // written, growing by one per plugin run), so the preflight's 4,096 would have
8
+ // switched recovery off within months; the cap is a guard against a
9
+ // pathological tree, not a size budget. opendir streams, nothing is buffered.
10
+ // Dot-entries (`.index-dirty`, `.index-cache`) are upstream index state, never
11
+ // workspaces, and are skipped without being counted. Directories whose mtime
12
+ // predates the spawn cannot have been created by this run and are skipped
13
+ // before any read, so the byte budget scales with concurrent activity, not
14
+ // with store size.
15
+ const DIR_ENUM_CAP = 65_536;
16
+ const STATE_MAX_BYTES = 1024 * 1024;
17
+ const JOURNAL_PREFIX_BYTES = 4 * 1024 * 1024; // The prompt is argv-bounded (< 1 MiB); the first user message follows a few config records.
18
+ const SCAN_MAX_BYTES = 64 * 1024 * 1024;
19
+ const MTIME_SLACK_MS = 1000; // Filesystems with coarse mtime granularity.
20
+ const SESSION_ID = /^session_[0-9a-f-]{36}$/;
21
+ /** Metadata recovery only, never a substitute for resume lineage/plan scans.
22
+ * A capped or unreadable enumeration cannot establish uniqueness and refuses;
23
+ * skipping symlinked or dot entries is not partial — neither can be a session
24
+ * the child created.
25
+ *
26
+ * A candidate is bound to THIS job by content, not only by time: the first
27
+ * user message in the session's main journal must carry a text item whose
28
+ * sha256 equals the job's `prompt_digest` (the exact `-p` argument). Time and
29
+ * cwd alone would admit a concurrent TUI session, another host's finished job
30
+ * (host-local stores cannot see each other's session ids), or a `state.json`
31
+ * planted by repository code running under rescue. The digest is not unique
32
+ * on its own either (the same prompt can run twice), so the window and the
33
+ * exactly-one rule stay in force. */
34
+ export async function recoverSessionIdFromStore(options) {
35
+ const entryCap = options.entryCap ?? DIR_ENUM_CAP;
36
+ let entries = 0;
37
+ let bytes = 0;
38
+ let digestMismatches = 0;
39
+ let missingJournals = 0;
40
+ const candidates = [];
41
+ const capped = new Error("enumeration_capped");
42
+ async function* directories(dir) {
43
+ if ((await lstat(dir)).isSymbolicLink())
44
+ throw new Error("unreadable");
45
+ const handle = await opendir(dir);
46
+ for await (const entry of handle) {
47
+ if (entry.name.startsWith("."))
48
+ continue;
49
+ if (++entries > entryCap)
50
+ throw capped;
51
+ // A symlinked entry is never a session the child created; skipping it
52
+ // keeps one stray link from disabling recovery host-wide. Directories
53
+ // we descend are still lstat-anchored above.
54
+ if (entry.isSymbolicLink())
55
+ continue;
56
+ if (entry.isDirectory())
57
+ yield entry.name;
58
+ }
59
+ }
60
+ // Bounded no-follow read of a regular file. Returns undefined when the file
61
+ // is absent; throws "unreadable" for anything that is not a plain file. With
62
+ // `prefix`, a larger file yields its first `maxBytes` instead of refusing.
63
+ async function readBounded(file, maxBytes, prefix = false) {
64
+ let handle;
65
+ try {
66
+ handle = await open(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
67
+ }
68
+ catch (error) {
69
+ if (error.code === "ENOENT")
70
+ return undefined;
71
+ throw error;
72
+ }
73
+ try {
74
+ const stat = await handle.stat();
75
+ if (!stat.isFile() || (stat.size > maxBytes && !prefix))
76
+ throw new Error("unreadable");
77
+ const size = Math.min(stat.size, maxBytes);
78
+ bytes += size;
79
+ if (bytes > SCAN_MAX_BYTES)
80
+ throw capped;
81
+ const buffer = Buffer.alloc(size);
82
+ let offset = 0;
83
+ while (offset < buffer.length) {
84
+ const read = await handle.read(buffer, offset, buffer.length - offset, offset);
85
+ if (!read.bytesRead)
86
+ break;
87
+ offset += read.bytesRead;
88
+ }
89
+ return buffer.subarray(0, offset);
90
+ }
91
+ finally {
92
+ await handle.close();
93
+ }
94
+ }
95
+ try {
96
+ if (!Number.isFinite(options.spawnedAt) || !Number.isFinite(options.settledAt) ||
97
+ options.settledAt < options.spawnedAt || !/^[0-9a-f]{64}$/.test(options.promptDigest)) {
98
+ return { reason: "none" };
99
+ }
100
+ const cwd = await realpath(options.cwd);
101
+ const sessions = path.join(options.kimiHome, "sessions");
102
+ // Missing nested dirs mean an incomplete scan; only a missing root is normal.
103
+ try {
104
+ await lstat(sessions);
105
+ }
106
+ catch (error) {
107
+ if (error.code === "ENOENT")
108
+ return { reason: "none" };
109
+ throw error;
110
+ }
111
+ for await (const workspace of directories(sessions)) {
112
+ const workspacePath = path.join(sessions, workspace);
113
+ for await (const session of directories(workspacePath)) {
114
+ if (!SESSION_ID.test(session))
115
+ continue;
116
+ const sessionPath = path.join(workspacePath, session);
117
+ // A directory this run created was modified at or after the spawn.
118
+ if ((await lstat(sessionPath)).mtimeMs < options.spawnedAt - MTIME_SLACK_MS)
119
+ continue;
120
+ const raw = await readBounded(path.join(sessionPath, "state.json"), STATE_MAX_BYTES);
121
+ if (!raw)
122
+ continue;
123
+ let state;
124
+ try {
125
+ state = JSON.parse(raw.toString("utf8"));
126
+ }
127
+ catch {
128
+ continue;
129
+ }
130
+ if (!state || typeof state !== "object")
131
+ continue;
132
+ const value = state;
133
+ // The child writes createdAt after the parent stamped spawnedAt on the
134
+ // same clock, so causality orders them; no pre-spawn slack is justified.
135
+ if (value.version !== 2 || typeof value.cwd !== "string" || !path.isAbsolute(value.cwd) ||
136
+ typeof value.id !== "string" || !SESSION_ID.test(value.id) || value.id !== session ||
137
+ typeof value.createdAt !== "number" || !Number.isFinite(value.createdAt) ||
138
+ value.createdAt < options.spawnedAt || value.createdAt > options.settledAt)
139
+ continue;
140
+ let stateCwd;
141
+ try {
142
+ stateCwd = await realpath(value.cwd);
143
+ }
144
+ catch {
145
+ continue;
146
+ }
147
+ if (stateCwd !== cwd || options.store.hasSessionId(value.id, options.jobId))
148
+ continue;
149
+ const journal = await readBounded(path.join(sessionPath, "agents", "main", "wire.jsonl"), JOURNAL_PREFIX_BYTES, true);
150
+ if (!journal) {
151
+ missingJournals += 1;
152
+ continue;
153
+ }
154
+ // A prefix cut mid-record must never be parsed as a complete line.
155
+ const text = journal.length === JOURNAL_PREFIX_BYTES
156
+ ? journal.subarray(0, journal.lastIndexOf(0x0a) + 1).toString("utf8") : journal.toString("utf8");
157
+ if (!firstUserMessageMatches(text, options.promptDigest)) {
158
+ digestMismatches += 1;
159
+ continue;
160
+ }
161
+ candidates.push(value.id);
162
+ }
163
+ }
164
+ if (candidates.length === 1)
165
+ return { sessionId: candidates[0] };
166
+ if (candidates.length > 1)
167
+ return { reason: `ambiguous:${candidates.length}` };
168
+ if (digestMismatches > 0)
169
+ return { reason: `digest_mismatch:${digestMismatches}` };
170
+ return { reason: missingJournals > 0 ? `journal_missing:${missingJournals}` : "none" };
171
+ }
172
+ catch (error) {
173
+ return { reason: error === capped ? "enumeration_capped" : "unreadable" };
174
+ }
175
+ }
176
+ /** True when the FIRST user message in a native-v2 main journal carries a
177
+ * text item equal to the prompt the job spawned with. Later user turns are
178
+ * never consulted: only the opening prompt binds a session to its spawn. */
179
+ export function firstUserMessageMatches(journal, promptDigest) {
180
+ for (const line of journal.split("\n")) {
181
+ if (!line.trim())
182
+ continue;
183
+ let record;
184
+ try {
185
+ record = JSON.parse(line);
186
+ }
187
+ catch {
188
+ continue;
189
+ }
190
+ if (!record || typeof record !== "object")
191
+ continue;
192
+ const message = record.message;
193
+ if (!message || typeof message !== "object" || message.role !== "user")
194
+ continue;
195
+ const content = message.content;
196
+ if (!Array.isArray(content))
197
+ return false;
198
+ return content.some((item) => item && typeof item === "object" && item.type === "text" &&
199
+ typeof item.text === "string" &&
200
+ digestPrompt(item.text) === promptDigest);
201
+ }
202
+ return false;
203
+ }
@@ -25,39 +25,68 @@
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
- let DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
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
29
  export class TomlDate extends Date {
30
30
  #hasDate = false;
31
31
  #hasTime = false;
32
32
  #offset = null;
33
- constructor(date) {
33
+ constructor(date, fasttype, unsafeDelim) {
34
34
  let hasDate = true;
35
35
  let hasTime = true;
36
36
  let offset = 'Z';
37
+ let c;
37
38
  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}`;
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;
43
65
  }
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 = '';
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
+ }
50
85
  }
51
86
  else {
52
- offset = match[3] || null;
53
- date = date.toUpperCase();
54
- if (!offset && hasTime)
55
- date += 'Z';
87
+ date = '';
56
88
  }
57
89
  }
58
- else {
59
- date = '';
60
- }
61
90
  }
62
91
  super(date);
63
92
  if (!isNaN(this.getTime())) {
@@ -93,7 +122,7 @@ export class TomlDate extends Date {
93
122
  if (this.#offset === null)
94
123
  return iso.slice(0, -1);
95
124
  // Offset DateTime
96
- if (this.#offset === 'Z')
125
+ if (this.#offset === 'Z' || this.#offset === 'z')
97
126
  return iso;
98
127
  // This part is quite annoying: JS strips the original timezone from the ISO string representation
99
128
  // Instead of using a "modified" date and "Z", we restore the representation "as authored"
@@ -26,11 +26,11 @@
26
26
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
  function getLineColFromPtr(string, ptr) {
29
- let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g);
29
+ let lines = string.slice(0, ptr).split(/\r?\n/);
30
30
  return [lines.length, lines.pop().length + 1];
31
31
  }
32
32
  function makeCodeBlock(string, line, column) {
33
- let lines = string.split(/\r\n|\n|\r/g);
33
+ let lines = string.split(/\r?\n/);
34
34
  let codeblock = '';
35
35
  let numberLen = (Math.log10(line + 1) | 0) + 1;
36
36
  for (let i = line - 1; i <= line + 1; i++) {
@@ -60,4 +60,8 @@ export class TomlError extends Error {
60
60
  this.column = column;
61
61
  this.codeblock = codeblock;
62
62
  }
63
+ /** @internal */
64
+ static x(message, ctx, ptr) {
65
+ throw new TomlError(message, { toml: ctx.s, ptr: ptr ?? ctx.p });
66
+ }
63
67
  }