From 54c5de97605fe720edfbbd5feac176d6615e9317 Mon Sep 17 00:00:00 2001 From: anor Date: Wed, 15 Jul 2026 21:09:14 +1000 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B0=D0=B3=D0=B5=D0=BD=D1=82=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=BF=D1=83=D1=82=D1=8C=20(Docker=20sandbox)=20?= =?UTF-8?q?=E2=80=94=20=D0=BF=D0=B0=D1=80=D0=B8=D1=82=D0=B5=D1=82=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B0=D0=BC=20.xl?= =?UTF-8?q?s/.doc/OCR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Паритет agent-пути с GLM: read_xlsx_sheet читает .xls через xlrd; в образ песочницы добавлены catdoc (.doc), tesseract-ocr+rus (OCR PDF), xlrd/pytesseract/pillow (pip). parse_gsfx_file/parse_arp_file уже доступны агенту (gge_tools/smeta_mcp монтируются). Образ smeta-claude-sandbox пересобран. Real-тест: read_xlsx_sheet(.xls) в песочнице → 1926 строк. Co-Authored-By: Claude Opus 4.8 (1M context) --- sandbox/Dockerfile | 7 +++++-- smeta_mcp.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/sandbox/Dockerfile b/sandbox/Dockerfile index 8852042..909fd6d 100644 --- a/sandbox/Dockerfile +++ b/sandbox/Dockerfile @@ -1,13 +1,16 @@ FROM node:22-slim # Python + libs for file processing + smeta-railway deps +# catdoc — старые .doc (OLE2); tesseract-ocr + rus — OCR PDF-сканов RUN apt-get update && apt-get install -y --no-install-recommends \ - python3 python3-pip python3-venv && \ + python3 python3-pip python3-venv \ + catdoc tesseract-ocr tesseract-ocr-rus && \ rm -rf /var/lib/apt/lists/* RUN pip3 install --break-system-packages --no-cache-dir \ openpyxl python-docx pymupdf pandas \ - faiss-cpu pyyaml pydantic typer openai rank-bm25 + faiss-cpu pyyaml pydantic typer openai rank-bm25 \ + xlrd pytesseract pillow # Claude Code CLI RUN npm install -g @anthropic-ai/claude-code diff --git a/smeta_mcp.py b/smeta_mcp.py index 1258fcb..fac6362 100644 --- a/smeta_mcp.py +++ b/smeta_mcp.py @@ -56,8 +56,35 @@ def tool_read_xlsx_sheet(*, filename: str, sheet: str | None = None, max_rows: i fpath = _work_dir(user, tab) / Path(filename).name if not fpath.exists(): return {"error": f"Файл «{filename}» не найден"} - if fpath.suffix.lower() not in {".xlsx", ".xlsm", ".xls"}: + ext = fpath.suffix.lower() + if ext not in {".xlsx", ".xlsm", ".xls"}: return {"error": f"Неподдерживаемый формат: {fpath.suffix}"} + if ext == ".xls": + # Легаси BIFF — openpyxl не умеет, читаем через xlrd. + try: + import xlrd + from openpyxl.utils import get_column_letter + except ImportError: + return {"error": "Чтение .xls требует xlrd (нет в окружении)"} + try: + book = xlrd.open_workbook(str(fpath)) + except Exception as e: + return {"error": f"Не удалось открыть .xls: {e}"} + names = book.sheet_names() + sh = book.sheet_by_name(sheet) if sheet in names else book.sheet_by_index(0) + rows_x: list[dict] = [] + real_x = 0 + for r in range(sh.nrows): + cells = {get_column_letter(c + 1): str(sh.cell_value(r, c))[:300] + for c in range(sh.ncols) + if str(sh.cell_value(r, c)).strip()} + if not cells: + continue + real_x += 1 + if len(rows_x) < max_rows: + rows_x.append({"row": r + 1, "cells": cells}) + return {"filename": fpath.name, "sheet": sh.name, "all_sheets": names, + "rows_with_data_total": real_x, "rows_returned": len(rows_x), "rows": rows_x} try: wb = openpyxl.load_workbook(str(fpath), data_only=True) except Exception as e: