feat: парсер .gsfx (ГРАНД-Смета новый формат) + MCP-tool parse_gsfx_file
Пункт 1 мастер-плана по анализу корпуса: .gsfx (555 файлов) не читался. .gsfx = zip с Properties.txt (шапка/итог cp1251) + Data.xml (позиции windows-1251). gge_tools.parse_gsfx_file достаёт code/name/region/total + позиции (Code/Caption/Units/Quantity.Result), XXE-safe (defusedxml→fallback). MCP-tool parse_gsfx_file + .gsfx в ALLOWED_EXTENSIONS обоих bridge. Real-тест поймал баг: русская запятая в Result (0,24) → _ru_float. Юнит mutation-safe + серверный real-тест на настоящем .gsfx (ЛС-07-01-01, 87 позиций, итог 16.1М). APP_VERSION→2026-07-15c. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -267,6 +267,33 @@ def tool_parse_gge_file(*, filename: str, max_positions: int = 30) -> dict:
|
||||
return data
|
||||
|
||||
|
||||
def tool_parse_gsfx_file(*, filename: str, max_positions: int = 30) -> dict:
|
||||
"""Распарсить одну .gsfx смету (ГРАНД-Смета, новый формат). filename —
|
||||
относительный путь в work_dir или внутри распакованной папки.
|
||||
|
||||
Возвращает: code, name, region, total (итог сметы), первые max_positions
|
||||
позиций (code=шифр ГЭСН/ФССЦ, name, unit, quantity). Родной формат
|
||||
ГРАНД-Сметы — до этого приложение его не читало.
|
||||
"""
|
||||
user, tab = _user_tab()
|
||||
work_dir = _work_dir(user, tab)
|
||||
candidate = work_dir / filename
|
||||
if not candidate.exists():
|
||||
matches = list(work_dir.rglob(Path(filename).name))
|
||||
if not matches:
|
||||
return {"error": f"«{filename}» не найден в {user}/{tab}"}
|
||||
candidate = matches[0]
|
||||
from gge_tools import parse_gsfx_file
|
||||
data = parse_gsfx_file(candidate)
|
||||
if 'error' in data:
|
||||
return data
|
||||
if len(data['positions']) > max_positions:
|
||||
data['positions_total'] = len(data['positions'])
|
||||
data['positions'] = data['positions'][:max_positions]
|
||||
data['positions_truncated'] = True
|
||||
return data
|
||||
|
||||
|
||||
def tool_update_xlsx_cells(*, filename: str, sheet: str,
|
||||
updates: list, out_filename: str | None = None) -> dict:
|
||||
"""Массовая запись ячеек в xlsx. Универсальный tool — годится для
|
||||
@@ -469,6 +496,24 @@ TOOLS: dict[str, dict] = {
|
||||
"required": ["filename"],
|
||||
},
|
||||
},
|
||||
"parse_gsfx_file": {
|
||||
"fn": tool_parse_gsfx_file,
|
||||
"description": (
|
||||
"Распарсить одну .gsfx смету (ГРАНД-Смета, НОВЫЙ формат — zip с "
|
||||
"Data.xml внутри). Возвращает: code (шифр ЛС), name, region, total "
|
||||
"(итог сметы, руб), positions (позиции: code=шифр ГЭСН/ФССЦ, name, "
|
||||
"unit, quantity). ИСПОЛЬЗУЙ для файлов .gsfx — это родной формат "
|
||||
"ГРАНД-Сметы, самой массовой сметной программы. Для .gge — parse_gge_file."
|
||||
),
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"filename": {"type": "string", "description": "Путь к .gsfx относительно work_dir (или basename — будет найден)"},
|
||||
"max_positions": {"type": "integer", "description": "Лимит позиций в ответе (default 30)"},
|
||||
},
|
||||
"required": ["filename"],
|
||||
},
|
||||
},
|
||||
"update_xlsx_cells": {
|
||||
"fn": tool_update_xlsx_cells,
|
||||
"description": (
|
||||
|
||||
Reference in New Issue
Block a user