@codelia/storage 0.1.39 → 0.1.40

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
@@ -771,7 +771,7 @@ var SessionStateStoreImpl = class {
771
771
  var import_node_fs5 = require("fs");
772
772
  var import_node_path5 = __toESM(require("path"), 1);
773
773
  var DEFAULT_MAX_MATCHES = 50;
774
- var DEFAULT_MAX_LINE_LENGTH = 5e4;
774
+ var DEFAULT_MAX_LINE_LENGTH = 1e3;
775
775
  var DEFAULT_MAX_READ_BYTES = 64 * 1024;
776
776
  var DEFAULT_MAX_GREP_BYTES = 64 * 1024;
777
777
  var DEFAULT_READ_LINE_CHAR_LIMIT = 1e4;
@@ -791,26 +791,6 @@ var parsePositiveIntEnv = (key) => {
791
791
  if (!Number.isFinite(parsed) || parsed <= 0) return void 0;
792
792
  return parsed;
793
793
  };
794
- var buildTooLargeToReadError = (options) => [
795
- `TOO_LARGE_TO_READ: output exceeds per-call limit (${options.maxReadBytes} bytes).`,
796
- `ref_id=${options.refId} offset=${options.offset} limit=${options.limit}`,
797
- "Try split reads:",
798
- `- tool_output_cache({"ref_id":"${options.refId}","offset":${options.offset},"limit":2000})`,
799
- `- tool_output_cache({"ref_id":"${options.refId}","offset":${options.nextOffset},"limit":2000})`
800
- ].join("\n").trim();
801
- var buildSingleLineByteCapError = (options) => [
802
- `TOO_LARGE_TO_READ: requested line ${options.lineNumber} exceeds per-call byte limit (${options.maxReadBytes} bytes).`,
803
- `ref_id=${options.refId} line_number=${options.lineNumber}`,
804
- "Offset-based pagination cannot continue within one physical line.",
805
- "Use tool_output_cache_line for char-based paging or retry with allow_truncate=true.",
806
- `tool_output_cache_line({"ref_id":"${options.refId}","line_number":${options.lineNumber},"char_offset":0,"char_limit":10000})`
807
- ].join("\n").trim();
808
- var buildLineTooLongError = (options) => [
809
- `LINE_TOO_LONG: line ${options.lineNumber} has ${options.lineLength} chars (max ${options.maxLineLength}).`,
810
- `ref_id=${options.refId}`,
811
- "Use tool_output_cache_line for char-based paging or retry with allow_truncate=true.",
812
- `tool_output_cache_line({"ref_id":"${options.refId}","line_number":${options.lineNumber},"char_offset":0,"char_limit":10000})`
813
- ].join("\n").trim();
814
794
  var clipLongLine = (line, maxLineLength) => {
815
795
  if (line.length <= maxLineLength) return line;
816
796
  return `${line.slice(0, maxLineLength)}...`;
@@ -837,18 +817,28 @@ var clipLineToByteBudget = (line, maxBytes) => {
837
817
  }
838
818
  return `${clipUtf8ToBytes(line, maxBytes - suffixBytes)}${suffix}`;
839
819
  };
820
+ var buildTruncatedLinesSummary = (lineNumbers) => {
821
+ if (lineNumbers.length === 0) return null;
822
+ if (lineNumbers.length > 3) {
823
+ return "[truncated lines: many]";
824
+ }
825
+ return `[truncated lines: ${lineNumbers.join(", ")}]`;
826
+ };
840
827
  var appendReadSuffix = (output, options) => {
841
828
  let next = output;
842
829
  if (options.truncatedByBytes || options.hasMoreLines) {
843
- const reason = options.truncatedByBytes ? `Output truncated at ${options.maxReadBytes} bytes.` : "Output has more lines.";
830
+ const reason = options.truncatedByBytes ? `[output truncated at ${options.maxReadBytes} bytes]` : "Output has more lines.";
844
831
  next += `
845
832
 
846
833
  ${reason} Use offset to read beyond line ${options.lastReadLine}.`;
847
834
  }
848
- if (options.clipped) {
835
+ const truncatedLinesSummary = buildTruncatedLinesSummary(
836
+ Array.from(new Set(options.truncatedLineNumbers))
837
+ );
838
+ if (truncatedLinesSummary) {
849
839
  next += `
850
840
 
851
- Long physical lines are clipped at ${options.maxLineLength} chars.`;
841
+ ${truncatedLinesSummary}`;
852
842
  }
853
843
  return next;
854
844
  };
@@ -895,28 +885,19 @@ var ToolOutputCacheStoreImpl = class {
895
885
  const lines = content.split(/\r?\n/);
896
886
  const offset = options.offset ?? 0;
897
887
  const limit = options.limit ?? lines.length;
898
- const allowTruncate = options.allow_truncate ?? false;
899
888
  if (offset >= lines.length) {
900
889
  return "Offset exceeds output length.";
901
890
  }
902
891
  const outputLines = [];
903
892
  let bytes = 0;
904
893
  let truncatedByBytes = false;
905
- let clipped = false;
894
+ const truncatedLineNumbers = [];
906
895
  let firstClippedLineNumber = null;
907
896
  for (let index = offset; index < Math.min(lines.length, offset + limit); index += 1) {
908
897
  const originalLine = lines[index] ?? "";
909
- if (originalLine.length > this.maxLineLength && !allowTruncate) {
910
- return buildLineTooLongError({
911
- refId: normalizeRefId(refId),
912
- lineNumber: index + 1,
913
- lineLength: originalLine.length,
914
- maxLineLength: this.maxLineLength
915
- });
916
- }
917
- const line = allowTruncate ? clipLongLine(originalLine, this.maxLineLength) : originalLine;
898
+ const line = clipLongLine(originalLine, this.maxLineLength);
918
899
  if (line.length !== originalLine.length) {
919
- clipped = true;
900
+ truncatedLineNumbers.push(index + 1);
920
901
  if (firstClippedLineNumber === null) {
921
902
  firstClippedLineNumber = index + 1;
922
903
  }
@@ -924,22 +905,6 @@ var ToolOutputCacheStoreImpl = class {
924
905
  const numberedLine = `${formatLineNumber(index + 1)} ${line}`;
925
906
  const size = Buffer.byteLength(numberedLine, "utf8") + (outputLines.length > 0 ? 1 : 0);
926
907
  if (bytes + size > this.maxReadBytes) {
927
- if (!allowTruncate) {
928
- if (outputLines.length === 0) {
929
- return buildSingleLineByteCapError({
930
- refId: normalizeRefId(refId),
931
- lineNumber: index + 1,
932
- maxReadBytes: this.maxReadBytes
933
- });
934
- }
935
- return buildTooLargeToReadError({
936
- refId: normalizeRefId(refId),
937
- offset,
938
- limit,
939
- maxReadBytes: this.maxReadBytes,
940
- nextOffset: Math.max(offset + outputLines.length, offset + 1)
941
- });
942
- }
943
908
  if (outputLines.length === 0) {
944
909
  const prefix = `${formatLineNumber(index + 1)} `;
945
910
  const budget = this.maxReadBytes - Buffer.byteLength(prefix, "utf8");
@@ -947,7 +912,7 @@ var ToolOutputCacheStoreImpl = class {
947
912
  if (clippedByBytes.length > 0) {
948
913
  outputLines.push(clippedByBytes);
949
914
  bytes = Buffer.byteLength(`${prefix}${clippedByBytes}`, "utf8");
950
- clipped = true;
915
+ truncatedLineNumbers.push(index + 1);
951
916
  if (firstClippedLineNumber === null) {
952
917
  firstClippedLineNumber = index + 1;
953
918
  }
@@ -966,10 +931,9 @@ var ToolOutputCacheStoreImpl = class {
966
931
  hasMoreLines,
967
932
  lastReadLine: offset + outputLines.length,
968
933
  maxReadBytes: this.maxReadBytes,
969
- clipped,
970
- maxLineLength: this.maxLineLength
934
+ truncatedLineNumbers
971
935
  }).concat(
972
- allowTruncate && firstClippedLineNumber !== null ? `
936
+ firstClippedLineNumber !== null ? `
973
937
 
974
938
  For full long-line content, use tool_output_cache_line({"ref_id":"${normalizeRefId(refId)}","line_number":${firstClippedLineNumber},"char_offset":0,"char_limit":10000}).` : ""
975
939
  );
package/dist/index.js CHANGED
@@ -727,7 +727,7 @@ var SessionStateStoreImpl = class {
727
727
  import { promises as fs5 } from "fs";
728
728
  import path5 from "path";
729
729
  var DEFAULT_MAX_MATCHES = 50;
730
- var DEFAULT_MAX_LINE_LENGTH = 5e4;
730
+ var DEFAULT_MAX_LINE_LENGTH = 1e3;
731
731
  var DEFAULT_MAX_READ_BYTES = 64 * 1024;
732
732
  var DEFAULT_MAX_GREP_BYTES = 64 * 1024;
733
733
  var DEFAULT_READ_LINE_CHAR_LIMIT = 1e4;
@@ -747,26 +747,6 @@ var parsePositiveIntEnv = (key) => {
747
747
  if (!Number.isFinite(parsed) || parsed <= 0) return void 0;
748
748
  return parsed;
749
749
  };
750
- var buildTooLargeToReadError = (options) => [
751
- `TOO_LARGE_TO_READ: output exceeds per-call limit (${options.maxReadBytes} bytes).`,
752
- `ref_id=${options.refId} offset=${options.offset} limit=${options.limit}`,
753
- "Try split reads:",
754
- `- tool_output_cache({"ref_id":"${options.refId}","offset":${options.offset},"limit":2000})`,
755
- `- tool_output_cache({"ref_id":"${options.refId}","offset":${options.nextOffset},"limit":2000})`
756
- ].join("\n").trim();
757
- var buildSingleLineByteCapError = (options) => [
758
- `TOO_LARGE_TO_READ: requested line ${options.lineNumber} exceeds per-call byte limit (${options.maxReadBytes} bytes).`,
759
- `ref_id=${options.refId} line_number=${options.lineNumber}`,
760
- "Offset-based pagination cannot continue within one physical line.",
761
- "Use tool_output_cache_line for char-based paging or retry with allow_truncate=true.",
762
- `tool_output_cache_line({"ref_id":"${options.refId}","line_number":${options.lineNumber},"char_offset":0,"char_limit":10000})`
763
- ].join("\n").trim();
764
- var buildLineTooLongError = (options) => [
765
- `LINE_TOO_LONG: line ${options.lineNumber} has ${options.lineLength} chars (max ${options.maxLineLength}).`,
766
- `ref_id=${options.refId}`,
767
- "Use tool_output_cache_line for char-based paging or retry with allow_truncate=true.",
768
- `tool_output_cache_line({"ref_id":"${options.refId}","line_number":${options.lineNumber},"char_offset":0,"char_limit":10000})`
769
- ].join("\n").trim();
770
750
  var clipLongLine = (line, maxLineLength) => {
771
751
  if (line.length <= maxLineLength) return line;
772
752
  return `${line.slice(0, maxLineLength)}...`;
@@ -793,18 +773,28 @@ var clipLineToByteBudget = (line, maxBytes) => {
793
773
  }
794
774
  return `${clipUtf8ToBytes(line, maxBytes - suffixBytes)}${suffix}`;
795
775
  };
776
+ var buildTruncatedLinesSummary = (lineNumbers) => {
777
+ if (lineNumbers.length === 0) return null;
778
+ if (lineNumbers.length > 3) {
779
+ return "[truncated lines: many]";
780
+ }
781
+ return `[truncated lines: ${lineNumbers.join(", ")}]`;
782
+ };
796
783
  var appendReadSuffix = (output, options) => {
797
784
  let next = output;
798
785
  if (options.truncatedByBytes || options.hasMoreLines) {
799
- const reason = options.truncatedByBytes ? `Output truncated at ${options.maxReadBytes} bytes.` : "Output has more lines.";
786
+ const reason = options.truncatedByBytes ? `[output truncated at ${options.maxReadBytes} bytes]` : "Output has more lines.";
800
787
  next += `
801
788
 
802
789
  ${reason} Use offset to read beyond line ${options.lastReadLine}.`;
803
790
  }
804
- if (options.clipped) {
791
+ const truncatedLinesSummary = buildTruncatedLinesSummary(
792
+ Array.from(new Set(options.truncatedLineNumbers))
793
+ );
794
+ if (truncatedLinesSummary) {
805
795
  next += `
806
796
 
807
- Long physical lines are clipped at ${options.maxLineLength} chars.`;
797
+ ${truncatedLinesSummary}`;
808
798
  }
809
799
  return next;
810
800
  };
@@ -851,28 +841,19 @@ var ToolOutputCacheStoreImpl = class {
851
841
  const lines = content.split(/\r?\n/);
852
842
  const offset = options.offset ?? 0;
853
843
  const limit = options.limit ?? lines.length;
854
- const allowTruncate = options.allow_truncate ?? false;
855
844
  if (offset >= lines.length) {
856
845
  return "Offset exceeds output length.";
857
846
  }
858
847
  const outputLines = [];
859
848
  let bytes = 0;
860
849
  let truncatedByBytes = false;
861
- let clipped = false;
850
+ const truncatedLineNumbers = [];
862
851
  let firstClippedLineNumber = null;
863
852
  for (let index = offset; index < Math.min(lines.length, offset + limit); index += 1) {
864
853
  const originalLine = lines[index] ?? "";
865
- if (originalLine.length > this.maxLineLength && !allowTruncate) {
866
- return buildLineTooLongError({
867
- refId: normalizeRefId(refId),
868
- lineNumber: index + 1,
869
- lineLength: originalLine.length,
870
- maxLineLength: this.maxLineLength
871
- });
872
- }
873
- const line = allowTruncate ? clipLongLine(originalLine, this.maxLineLength) : originalLine;
854
+ const line = clipLongLine(originalLine, this.maxLineLength);
874
855
  if (line.length !== originalLine.length) {
875
- clipped = true;
856
+ truncatedLineNumbers.push(index + 1);
876
857
  if (firstClippedLineNumber === null) {
877
858
  firstClippedLineNumber = index + 1;
878
859
  }
@@ -880,22 +861,6 @@ var ToolOutputCacheStoreImpl = class {
880
861
  const numberedLine = `${formatLineNumber(index + 1)} ${line}`;
881
862
  const size = Buffer.byteLength(numberedLine, "utf8") + (outputLines.length > 0 ? 1 : 0);
882
863
  if (bytes + size > this.maxReadBytes) {
883
- if (!allowTruncate) {
884
- if (outputLines.length === 0) {
885
- return buildSingleLineByteCapError({
886
- refId: normalizeRefId(refId),
887
- lineNumber: index + 1,
888
- maxReadBytes: this.maxReadBytes
889
- });
890
- }
891
- return buildTooLargeToReadError({
892
- refId: normalizeRefId(refId),
893
- offset,
894
- limit,
895
- maxReadBytes: this.maxReadBytes,
896
- nextOffset: Math.max(offset + outputLines.length, offset + 1)
897
- });
898
- }
899
864
  if (outputLines.length === 0) {
900
865
  const prefix = `${formatLineNumber(index + 1)} `;
901
866
  const budget = this.maxReadBytes - Buffer.byteLength(prefix, "utf8");
@@ -903,7 +868,7 @@ var ToolOutputCacheStoreImpl = class {
903
868
  if (clippedByBytes.length > 0) {
904
869
  outputLines.push(clippedByBytes);
905
870
  bytes = Buffer.byteLength(`${prefix}${clippedByBytes}`, "utf8");
906
- clipped = true;
871
+ truncatedLineNumbers.push(index + 1);
907
872
  if (firstClippedLineNumber === null) {
908
873
  firstClippedLineNumber = index + 1;
909
874
  }
@@ -922,10 +887,9 @@ var ToolOutputCacheStoreImpl = class {
922
887
  hasMoreLines,
923
888
  lastReadLine: offset + outputLines.length,
924
889
  maxReadBytes: this.maxReadBytes,
925
- clipped,
926
- maxLineLength: this.maxLineLength
890
+ truncatedLineNumbers
927
891
  }).concat(
928
- allowTruncate && firstClippedLineNumber !== null ? `
892
+ firstClippedLineNumber !== null ? `
929
893
 
930
894
  For full long-line content, use tool_output_cache_line({"ref_id":"${normalizeRefId(refId)}","line_number":${firstClippedLineNumber},"char_offset":0,"char_limit":10000}).` : ""
931
895
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codelia/storage",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
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.39",
27
- "@codelia/shared-types": "0.1.39",
26
+ "@codelia/core": "0.1.40",
27
+ "@codelia/shared-types": "0.1.40",
28
28
  "better-sqlite3": "^12.6.2"
29
29
  },
30
30
  "publishConfig": {