@codelia/storage 0.1.54 → 0.1.55

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.cjs CHANGED
@@ -992,6 +992,10 @@ var DEFAULT_MAX_READ_BYTES = 64 * 1024;
992
992
  var DEFAULT_MAX_GREP_BYTES = 64 * 1024;
993
993
  var DEFAULT_READ_LINE_CHAR_LIMIT = 1e4;
994
994
  var MAX_READ_LINE_CHAR_LIMIT = 1e5;
995
+ var GRAPHEME_SEGMENTER = new Intl.Segmenter(void 0, {
996
+ granularity: "grapheme"
997
+ });
998
+ var splitGraphemes = (value) => Array.from(GRAPHEME_SEGMENTER.segment(value), ({ segment }) => segment);
995
999
  var normalizeRefId = (refId) => refId.replace(/[^a-zA-Z0-9_-]/g, "_");
996
1000
  var formatLineNumber = (lineNumber) => String(lineNumber).padStart(5, " ");
997
1001
  var toLineNumbered = (lines, offset) => lines.map((line, index) => `${formatLineNumber(index + offset + 1)} ${line}`).join("\n");
@@ -1177,6 +1181,7 @@ For full long-line content, use tool_output_cache_line({"ref_id":"${normalizeRef
1177
1181
  return `Line number out of range: ${options.line_number} (total ${lines.length})`;
1178
1182
  }
1179
1183
  const line = lines[lineIndex] ?? "";
1184
+ const chars = splitGraphemes(line);
1180
1185
  const charOffset = Math.max(0, options.char_offset ?? 0);
1181
1186
  const charLimit = Math.max(
1182
1187
  1,
@@ -1185,16 +1190,17 @@ For full long-line content, use tool_output_cache_line({"ref_id":"${normalizeRef
1185
1190
  MAX_READ_LINE_CHAR_LIMIT
1186
1191
  )
1187
1192
  );
1188
- if (charOffset > line.length) {
1189
- return `char_offset out of range: ${charOffset} (line length ${line.length})`;
1193
+ if (charOffset > chars.length) {
1194
+ return `char_offset out of range: ${charOffset} (line length ${chars.length})`;
1190
1195
  }
1191
- const segment = line.slice(charOffset, charOffset + charLimit);
1192
- const endOffset = charOffset + segment.length;
1193
- const hasMore = endOffset < line.length;
1196
+ const segmentChars = chars.slice(charOffset, charOffset + charLimit);
1197
+ const segment = segmentChars.join("");
1198
+ const endOffset = charOffset + segmentChars.length;
1199
+ const hasMore = endOffset < chars.length;
1194
1200
  let output = [
1195
1201
  `ref_id=${normalizeRefId(refId)}`,
1196
1202
  `line_number=${options.line_number}`,
1197
- `line_length=${line.length}`,
1203
+ `line_length=${chars.length}`,
1198
1204
  `char_range=${charOffset}..${Math.max(endOffset - 1, charOffset - 1)}`,
1199
1205
  segment
1200
1206
  ].join("\n");
package/dist/index.js CHANGED
@@ -947,6 +947,10 @@ var DEFAULT_MAX_READ_BYTES = 64 * 1024;
947
947
  var DEFAULT_MAX_GREP_BYTES = 64 * 1024;
948
948
  var DEFAULT_READ_LINE_CHAR_LIMIT = 1e4;
949
949
  var MAX_READ_LINE_CHAR_LIMIT = 1e5;
950
+ var GRAPHEME_SEGMENTER = new Intl.Segmenter(void 0, {
951
+ granularity: "grapheme"
952
+ });
953
+ var splitGraphemes = (value) => Array.from(GRAPHEME_SEGMENTER.segment(value), ({ segment }) => segment);
950
954
  var normalizeRefId = (refId) => refId.replace(/[^a-zA-Z0-9_-]/g, "_");
951
955
  var formatLineNumber = (lineNumber) => String(lineNumber).padStart(5, " ");
952
956
  var toLineNumbered = (lines, offset) => lines.map((line, index) => `${formatLineNumber(index + offset + 1)} ${line}`).join("\n");
@@ -1132,6 +1136,7 @@ For full long-line content, use tool_output_cache_line({"ref_id":"${normalizeRef
1132
1136
  return `Line number out of range: ${options.line_number} (total ${lines.length})`;
1133
1137
  }
1134
1138
  const line = lines[lineIndex] ?? "";
1139
+ const chars = splitGraphemes(line);
1135
1140
  const charOffset = Math.max(0, options.char_offset ?? 0);
1136
1141
  const charLimit = Math.max(
1137
1142
  1,
@@ -1140,16 +1145,17 @@ For full long-line content, use tool_output_cache_line({"ref_id":"${normalizeRef
1140
1145
  MAX_READ_LINE_CHAR_LIMIT
1141
1146
  )
1142
1147
  );
1143
- if (charOffset > line.length) {
1144
- return `char_offset out of range: ${charOffset} (line length ${line.length})`;
1148
+ if (charOffset > chars.length) {
1149
+ return `char_offset out of range: ${charOffset} (line length ${chars.length})`;
1145
1150
  }
1146
- const segment = line.slice(charOffset, charOffset + charLimit);
1147
- const endOffset = charOffset + segment.length;
1148
- const hasMore = endOffset < line.length;
1151
+ const segmentChars = chars.slice(charOffset, charOffset + charLimit);
1152
+ const segment = segmentChars.join("");
1153
+ const endOffset = charOffset + segmentChars.length;
1154
+ const hasMore = endOffset < chars.length;
1149
1155
  let output = [
1150
1156
  `ref_id=${normalizeRefId(refId)}`,
1151
1157
  `line_number=${options.line_number}`,
1152
- `line_length=${line.length}`,
1158
+ `line_length=${chars.length}`,
1153
1159
  `char_range=${charOffset}..${Math.max(endOffset - 1, charOffset - 1)}`,
1154
1160
  segment
1155
1161
  ].join("\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codelia/storage",
3
- "version": "0.1.54",
3
+ "version": "0.1.55",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=20 <25"
@@ -23,8 +23,8 @@
23
23
  "typecheck": "tsc --noEmit"
24
24
  },
25
25
  "dependencies": {
26
- "@codelia/core": "0.1.54",
27
- "@codelia/shared-types": "0.1.54",
26
+ "@codelia/core": "0.1.55",
27
+ "@codelia/shared-types": "0.1.55",
28
28
  "better-sqlite3": "^12.6.2"
29
29
  },
30
30
  "publishConfig": {