buckyos 0.7.191 → 0.7.192

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.
@@ -1018,13 +1018,20 @@ const EDIT_FILE_SPEC = {
1018
1018
  type: "object"
1019
1019
  }
1020
1020
  };
1021
- async function readText(path) {
1021
+ async function readRaw(path) {
1022
1022
  try {
1023
- return decodeLossy(await deno().readFile(path));
1023
+ return await deno().readFile(path);
1024
1024
  } catch (e) {
1025
1025
  throw execFailed(`read file failed: ${errorText(e)}`);
1026
1026
  }
1027
1027
  }
1028
+ async function readText(path) {
1029
+ return decodeLossy(await readRaw(path));
1030
+ }
1031
+ const BINARY_PROBE_BYTES = 8192;
1032
+ function looksBinary(bytes) {
1033
+ return bytes.subarray(0, BINARY_PROBE_BYTES).includes(0);
1034
+ }
1028
1035
  async function writeText(path, text) {
1029
1036
  try {
1030
1037
  await deno().mkdir(parentDir(path), { recursive: true });
@@ -1060,7 +1067,11 @@ function readFileTool(cfg) {
1060
1067
  if (!filePath)
1061
1068
  throw invalidArgs("missing required arg `path`");
1062
1069
  const abs = await resolvePath(cfg.root, filePath, cfg.allowedRead);
1063
- const full = await readText(abs);
1070
+ const raw = await readRaw(abs);
1071
+ if (looksBinary(raw)) {
1072
+ throw invalidArgs(`\`${filePath}\` is a binary file (${raw.length} bytes): read_file only reads text. Use llm_understand_media for images, PDFs and office documents, or a shell command that converts or inspects the format.`);
1073
+ }
1074
+ const full = decodeLossy(raw);
1064
1075
  let chunk;
1065
1076
  let matched = true;
1066
1077
  let chunkStart = 1;