acp-kernel 0.0.67-pr.271.131 → 0.0.67-pr.274.133

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3827,8 +3827,7 @@ function parseObjectValue(value, callId, diag) {
3827
3827
  } else if (typeof content === "string") {
3828
3828
  const parsed = parseContentArray(content);
3829
3829
  if (parsed === null || parsed.entries.length === 0 && content.trim().length > 0) {
3830
- const bare = stripJsonWrapperResidue(content);
3831
- const entries2 = splitLineEntries(bare);
3830
+ const entries2 = splitLineEntries(content);
3832
3831
  const { ranges: ranges2, invalid: invalid2, reasons: reasons2 } = validateEntries(entries2, callId);
3833
3832
  if (ranges2.length > 0) {
3834
3833
  diag.invalidItems = invalid2;
@@ -3956,17 +3955,9 @@ function deriveTopicFromSummary(summary) {
3956
3955
  return text.length > 60 ? text.slice(0, 60).trimEnd() : text;
3957
3956
  }
3958
3957
  function splitLineEntries(content) {
3959
- const parts = content.split(/\n(?=\s*(?:["']\s*,\s*)?["']?\s*[mb]\d{1,7}\s*(?:[-\u2013\u2014\u2026~]|\.\.\.|to)\s*[mb]\d{1,7}\b)/i).map((p) => p.trim().replace(/^(?:["']\s*,?\s*)+/, "").replace(/["']\s*$/, "")).filter((p) => p.length > 0);
3958
+ const parts = content.split(/\n(?=[mb]\d{1,7}\s*(?:[-\u2013\u2014\u2026~]|\.\.\.|to)\s*[mb]\d{1,7}\b)/i).map((p) => p.trim()).filter((p) => p.length > 0);
3960
3959
  return parts.length > 0 ? parts : [content.trim()];
3961
3960
  }
3962
- function stripJsonWrapperResidue(s) {
3963
- let t = s.trim();
3964
- if (t.startsWith("[")) t = t.replace(/^\[+\s*/, "");
3965
- t = t.replace(/^"/, "");
3966
- if (t.endsWith("]")) t = t.replace(/\s*\]+$/, "");
3967
- t = t.replace(/"$/, "");
3968
- return t.trim();
3969
- }
3970
3961
  function validateEntry(entry, callId) {
3971
3962
  if (typeof entry === "string") return parseLineEntry(entry, callId);
3972
3963
  if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return { reason: "not an object" };
@@ -4009,15 +4000,49 @@ function tryParseLenient(s) {
4009
4000
  } catch {
4010
4001
  }
4011
4002
  }
4012
- const ctrlFixed = repairAtParserPositions(noTrailingCommas);
4013
- if (ctrlFixed !== noTrailingCommas) {
4003
+ return repairByParserPosition(noTrailingCommas);
4004
+ }
4005
+ function repairByParserPosition(s) {
4006
+ let cur = s;
4007
+ for (let i = 0; i <= cur.length; i++) {
4014
4008
  try {
4015
- return JSON.parse(ctrlFixed);
4016
- } catch {
4009
+ return JSON.parse(cur);
4010
+ } catch (e) {
4011
+ const msg = e instanceof Error ? e.message : String(e);
4012
+ const posMatch = /position (\d+)/.exec(msg);
4013
+ if (posMatch === null) return void 0;
4014
+ const pos = Number(posMatch[1]);
4015
+ if (/Bad control character/.test(msg)) {
4016
+ const cp = cur.codePointAt(pos);
4017
+ if (cp === void 0) return void 0;
4018
+ const adv = cp > 65535 ? 2 : 1;
4019
+ cur = cur.slice(0, pos) + escapeControlChar(cp) + cur.slice(pos + adv);
4020
+ } else if (/Bad escaped character/.test(msg)) {
4021
+ if (pos < 1 || cur.charAt(pos - 1) !== "\\") return void 0;
4022
+ cur = cur.slice(0, pos - 1) + "\\" + cur.slice(pos - 1);
4023
+ } else {
4024
+ return void 0;
4025
+ }
4017
4026
  }
4018
4027
  }
4019
4028
  return void 0;
4020
4029
  }
4030
+ function escapeControlChar(cp) {
4031
+ switch (cp) {
4032
+ case 8:
4033
+ return "\\b";
4034
+ case 9:
4035
+ return "\\t";
4036
+ case 10:
4037
+ return "\\n";
4038
+ case 12:
4039
+ return "\\f";
4040
+ case 13:
4041
+ return "\\r";
4042
+ default:
4043
+ return "\\u" + cp.toString(16).padStart(4, "0");
4044
+ }
4045
+ }
4021
4046
  function normalizeSingleQuotes(raw) {
4022
4047
  if (!raw.includes("'") || !raw.includes("{") && !raw.includes("[")) return void 0;
4023
4048
  let out = "";
@@ -4156,40 +4181,6 @@ function escapeRawNewlinesInStrings(s) {
4156
4181
  }
4157
4182
  return out;
4158
4183
  }
4159
- function repairAtParserPositions(s) {
4160
- let cur = s;
4161
- for (let i = 0; i < 500; i++) {
4162
- let err;
4163
- try {
4164
- JSON.parse(cur);
4165
- return cur;
4166
- } catch (e) {
4167
- err = e;
4168
- }
4169
- const msg = err instanceof Error ? err.message : String(err);
4170
- const posMatch = /position (\d+)/.exec(msg);
4171
- if (posMatch === null) return cur;
4172
- const pos = Number(posMatch[1]);
4173
- if (!Number.isInteger(pos) || pos < 0 || pos >= cur.length) return cur;
4174
- if (/control character/i.test(msg)) {
4175
- const ch = cur.charAt(pos);
4176
- let esc;
4177
- if (ch === "\n") esc = "\\n";
4178
- else if (ch === "\r") esc = "\\r";
4179
- else if (ch === " ") esc = "\\t";
4180
- else if (ch.charCodeAt(0) < 32) esc = "\\u" + ch.charCodeAt(0).toString(16).padStart(4, "0");
4181
- if (esc === void 0) return cur;
4182
- cur = cur.slice(0, pos) + esc + cur.slice(pos + 1);
4183
- } else if (/Bad escaped character/i.test(msg)) {
4184
- const b = cur.charAt(pos - 1) === "\\" ? pos - 1 : cur.charAt(pos) === "\\" ? pos : -1;
4185
- if (b < 0) return cur;
4186
- cur = cur.slice(0, b) + "\\\\" + cur.slice(b + 1);
4187
- } else {
4188
- return cur;
4189
- }
4190
- }
4191
- return cur;
4192
- }
4193
4184
  function looksTruncated(s) {
4194
4185
  let depth = 0;
4195
4186
  let inString = false;