[feat] solution/backend: 대화로 섹션 옮기기·숨기기 확장 — 앞·한 칸·N번째·자리 바꾸기 · 여러 개 끄기 · 꺼진 목록
"맨 위 · 맨 아래 · X 다음으로" 만 되고 "X 앞으로" "한 칸 위로" "세 번째로" "자리 바꿔줘" 는
거절됐다. 발행본(HomePage.tsx)은 히어로를 늘 맨 위, SNS 를 늘 맨 아래에 그리는데 대화는
그 둘을 옮기고 "옮겼습니다" 라고 답했다 — 화면은 그대로였다.
- tools: move_section 에 where(맨 위·맨 아래·앞·뒤·위로·아래로·번째·바꾸기)·count —
where 가 비면 예전 to 표기로 읽는다. 한 칸·N번째는 보이는 순서로 센다(꺼진 부분과 자리만
바꾸는 헛이동 방지). 없는 순번·꺼진 부분의 칸 이동은 거절, 이미 그 자리면 Unchanged
- tools: PINNED(히어로 맨 위 · SNS 맨 아래) — 옮기기와 그 둘을 기준으로 한 앞·뒤·바꾸기를 막는다.
히어로 다음은 맨 위, SNS 앞은 맨 아래로 읽는다
- tools: toggle_section 이 쉼표로 여럿을 받는다 — 하나라도 못 찾거나 잠겼으면 아무것도 안 바꾼다
- tools: list_sections 는 보이는 순서에 번호(= N번째 기준)를 붙이고 꺼진 것을 모은다, only=꺼진
- prompts/runtime: 스키마에 where·count·only, 섹션 줄에 [항상 맨 위]·[항상 맨 아래] —
목록은 tools.PINNED 하나를 runtime 이 넘긴다(prompts 는 services 를 import 하지 않는다)
- docs/AGENT.md: 옮기기·숨기기 표와 근거. 동작하지 않던 예시("후기 빼줘") 교체 —
이용 후기는 섹션 목록에 없고 발행본이 늘 그린다
테스트 21건 추가, 에이전트·카카오 174 passed. pyflakes 새 경고 없음
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4b48be7e81
commit
36b818eda3
5 files changed
+413
-33
No files matched your search
@@ -108,6 +108,7 @@ async def _choose(place, fields, facts, sections, photos, message) -> dict:
|
||||
sections=sections,
|
||||
photos=photos,
|
||||
message=message,
|
||||
pinned=registry.PINNED,
|
||||
),
|
||||
response_schema=prompt.RESPONSE_SCHEMA,
|
||||
temperature=0.0,
|
||||
|
||||
@@ -321,61 +321,204 @@ def _switch(raw: str) -> bool | None:
|
||||
return None
|
||||
|
||||
|
||||
def _layout_line(row: dict) -> str:
|
||||
mark = "켜짐" if row["enabled"] else "꺼짐"
|
||||
lock = " (항상 켜짐)" if row["locked"] else ""
|
||||
return f"· {row['name']} — {mark}{lock}"
|
||||
# ★ 발행본(site/src/pages/HomePage.tsx)은 이 둘을 배열 순서와 상관없이 그린다 — 히어로는 늘
|
||||
# 맨 위, SNS 게시글은 늘 맨 아래. 옮기게 두면 "옮겼습니다" 라고 말하는데 화면은 그대로다.
|
||||
PINNED = {"hero": "맨 위", "social": "맨 아래"}
|
||||
|
||||
# move_section 의 where. ★ '위' 는 한 칸 위다 — '맨 위' 와 가른다(예전 to 표기는 아래 _LEGACY_TO).
|
||||
_WHERE = {
|
||||
"top": {"맨 위", "맨위", "처음", "top", "first"},
|
||||
"bottom": {"맨 아래", "맨아래", "마지막", "bottom", "last"},
|
||||
"before": {"앞", "앞으로", "before"},
|
||||
"after": {"뒤", "뒤로", "다음", "다음으로", "after"},
|
||||
"up": {"위", "위로", "up"},
|
||||
"down": {"아래", "아래로", "down"},
|
||||
"nth": {"번째", "순서", "nth"},
|
||||
"swap": {"바꾸기", "자리 바꾸기", "교환", "swap"},
|
||||
}
|
||||
# where 가 없던 때의 표기 — to 에 '맨 위' · '맨 아래' 또는 "그 뒤에 올 부분의 이름" 이 왔다.
|
||||
_LEGACY_TO = {"맨 위": "top", "처음": "top", "위": "top", "top": "top", "first": "top",
|
||||
"맨 아래": "bottom", "마지막": "bottom", "아래": "bottom", "bottom": "bottom", "last": "bottom"}
|
||||
_KOREAN_COUNT = {"한": 1, "하나": 1, "두": 2, "둘": 2, "세": 3, "셋": 3, "네": 4, "넷": 4,
|
||||
"다섯": 5, "여섯": 6, "일곱": 7, "여덟": 8, "아홉": 9, "열": 10}
|
||||
|
||||
|
||||
def _where(raw: str) -> str | None:
|
||||
word = raw.strip().lower()
|
||||
return next((key for key, words in _WHERE.items() if word in words), None)
|
||||
|
||||
|
||||
def _count(raw: str) -> int | None:
|
||||
""""3" · "세" · "3칸" · "세 번째" → 3."""
|
||||
word = re.sub(r"\s|칸|번째|번|째", "", raw)
|
||||
if word.isdigit():
|
||||
return int(word)
|
||||
return _KOREAN_COUNT.get(word)
|
||||
|
||||
|
||||
def _visible_rows(rows: list) -> list:
|
||||
"""손님 화면의 순서 — 켜진 것, 자리가 고정된 둘을 뺀 것.
|
||||
|
||||
★ '한 칸 위' · 'N번째' 는 이 순서로 센다. 꺼진 부분은 화면에 없어서, 배열로 세면 꺼진
|
||||
부분과 자리만 바꾸고 화면은 그대로인 이동이 생긴다."""
|
||||
return [r for r in rows if r["enabled"] and r["id"] not in PINNED]
|
||||
|
||||
|
||||
def _insert(rows: list, row: dict, before: dict | None = None, after: dict | None = None) -> list:
|
||||
rest = [r for r in rows if r["id"] != row["id"]]
|
||||
at = rest.index(before) if before is not None else rest.index(after) + 1
|
||||
return rest[:at] + [row] + rest[at:]
|
||||
|
||||
|
||||
async def _list_sections(ctx: ToolContext, args: dict) -> str:
|
||||
"""보이는 순서에 번호를 붙이고, 꺼진 것은 따로 모은다.
|
||||
|
||||
★ 번호는 move_section 의 'N번째' 와 같은 순서다(_visible_rows) — 목록에서 본 번호로
|
||||
말했는데 다른 자리로 가면 사장님은 기능이 고장난 줄 안다."""
|
||||
rows, _theme = await _sections_of(ctx)
|
||||
body = "\n".join(_layout_line(r) for r in rows)
|
||||
return f"지금 홈페이지는 위에서부터 이 순서입니다.\n{body}"
|
||||
hidden = [r["name"] for r in rows if not r["enabled"]]
|
||||
hidden_line = f"꺼져 있는 부분: {', '.join(hidden)}" if hidden else "꺼져 있는 부분은 없어요."
|
||||
if _arg(args, "only") in ("꺼진", "꺼짐", "숨긴", "숨김", "hidden", "off"):
|
||||
return hidden_line
|
||||
|
||||
lines = [f"· {r['name']} — 항상 맨 위" for r in rows if r["id"] == "hero"]
|
||||
for i, r in enumerate(_visible_rows(rows), start=1):
|
||||
lines.append(f"{i}. {r['name']}" + (" (끌 수 없음)" if r["locked"] else ""))
|
||||
lines += [f"· {r['name']} — 항상 맨 아래" for r in rows if r["id"] == "social" and r["enabled"]]
|
||||
body = "\n".join(lines)
|
||||
return f"지금 홈페이지는 위에서부터 이 순서입니다.\n{body}\n{hidden_line}"
|
||||
|
||||
|
||||
async def _toggle_section(ctx: ToolContext, args: dict) -> str:
|
||||
"""켜거나 끈다. name 에 쉼표로 여럿을 받는다("사진 갤러리, 날씨").
|
||||
|
||||
★ 여럿 중 하나라도 못 찾거나 끌 수 없으면 **아무것도 바꾸지 않는다.** 일부만 끄면
|
||||
사장님은 무엇이 꺼졌는지 다시 확인해야 한다 — 한 요청은 한꺼번에 되거나 안 된다."""
|
||||
rows, theme = await _sections_of(ctx)
|
||||
row = _find_section(rows, _arg(args, "name"))
|
||||
if row is None:
|
||||
wanted = [w.strip() for w in re.split(r"[,·、]", _arg(args, "name")) if w.strip()]
|
||||
found, missing = [], []
|
||||
for name in wanted:
|
||||
row = _find_section(rows, name)
|
||||
if row is None:
|
||||
missing.append(name)
|
||||
elif row not in found:
|
||||
found.append(row)
|
||||
if missing or not found:
|
||||
if len(wanted) > 1:
|
||||
raise ToolRejected(f"{', '.join(missing)} 은(는) 어느 부분인지 못 찾아서 아무것도 바꾸지 않았어요. "
|
||||
f"'목록' 이라고 하시면 보여드릴게요.")
|
||||
raise ToolRejected("어느 부분을 말씀하시는지 못 찾았어요. '목록' 이라고 하시면 보여드릴게요.")
|
||||
|
||||
names = ", ".join(r["name"] for r in found)
|
||||
on = _switch(_arg(args, "enabled"))
|
||||
if on is None:
|
||||
raise ToolRejected(f"{row['name']} 을(를) 켤지 끌지 알려 주세요.")
|
||||
raise ToolRejected(f"{names} 을(를) 켤지 끌지 알려 주세요.")
|
||||
# ★ 잠긴 섹션은 끌 수 없다. SEO·필수 마크업 때문에 잠긴 것이라, 끄면 발행 게이트에 걸린다
|
||||
# (site_payload._sections 가 어차피 켜서 내보낸다 — 화면만 거짓말하게 된다).
|
||||
if row["locked"] and not on:
|
||||
raise ToolRejected(f"{row['name']} 은(는) 홈페이지에 꼭 있어야 하는 부분이라 끌 수 없어요.")
|
||||
if row["enabled"] == on:
|
||||
return Unchanged(f"{row['name']} 은(는) 이미 {'켜져' if on else '꺼져'} 있어요.")
|
||||
locked = [r["name"] for r in found if r["locked"]]
|
||||
if locked and not on:
|
||||
tail = " 아무것도 바꾸지 않았어요." if len(found) > 1 else ""
|
||||
raise ToolRejected(f"{', '.join(locked)} 은(는) 홈페이지에 꼭 있어야 하는 부분이라 끌 수 없어요.{tail}")
|
||||
|
||||
row["enabled"] = on
|
||||
todo = [r for r in found if r["enabled"] != on]
|
||||
already = [r["name"] for r in found if r["enabled"] == on]
|
||||
state = "켜져" if on else "꺼져"
|
||||
if not todo:
|
||||
return Unchanged(f"{', '.join(already)} 은(는) 이미 {state} 있어요.")
|
||||
|
||||
for r in todo:
|
||||
r["enabled"] = on
|
||||
await _save_sections(ctx, theme, rows)
|
||||
return f"{row['name']} 을(를) {'켰습니다' if on else '껐습니다'}."
|
||||
line = f"{', '.join(r['name'] for r in todo)} 을(를) {'켰습니다' if on else '껐습니다'}."
|
||||
return f"{line} ({', '.join(already)} 은(는) 이미 {state} 있었어요.)" if already else line
|
||||
|
||||
|
||||
async def _move_section(ctx: ToolContext, args: dict) -> str:
|
||||
"""★ 배열 순서가 곧 발행본의 섹션 순서다(site_payload._sections)."""
|
||||
"""★ 배열 순서가 곧 발행본의 섹션 순서다(site_payload._sections).
|
||||
|
||||
where: 맨 위 · 맨 아래 · 앞 · 뒤 · 위로/아래로(count 칸) · 번째(count 번째) · 바꾸기.
|
||||
where 가 비면 예전 표기(to 에 '맨 위' · '맨 아래' · 그 뒤에 올 이름)로 읽는다."""
|
||||
rows, theme = await _sections_of(ctx)
|
||||
row = _find_section(rows, _arg(args, "name"))
|
||||
if row is None:
|
||||
raise ToolRejected("어느 부분을 말씀하시는지 못 찾았어요. '목록' 이라고 하시면 보여드릴게요.")
|
||||
if row["id"] in PINNED:
|
||||
raise ToolRejected(f"{row['name']} 은(는) 항상 {PINNED[row['id']]}에 서는 부분이라 옮길 수 없어요.")
|
||||
|
||||
to = _arg(args, "to")
|
||||
rest = [r for r in rows if r["id"] != row["id"]]
|
||||
if to in ("맨 위", "처음", "위", "top", "first"):
|
||||
moved, where = [row] + rest, "맨 위로"
|
||||
elif to in ("맨 아래", "마지막", "아래", "bottom", "last"):
|
||||
moved, where = rest + [row], "맨 아래로"
|
||||
where = _where(_arg(args, "where")) or _LEGACY_TO.get(to) or ("after" if to else None)
|
||||
if where is None:
|
||||
raise ToolRejected("어디로 옮길지 알려 주세요. 예) 맨 위로 · 소개 다음으로 · 한 칸 위로 · 세 번째로")
|
||||
|
||||
if where in ("up", "down", "nth"):
|
||||
moved, said = _move_in_view(rows, row, where, _arg(args, "count"))
|
||||
if isinstance(moved, Unchanged):
|
||||
return moved
|
||||
elif where == "top":
|
||||
moved, said = [row] + [r for r in rows if r["id"] != row["id"]], "맨 위로"
|
||||
elif where == "bottom":
|
||||
moved, said = [r for r in rows if r["id"] != row["id"]] + [row], "맨 아래로"
|
||||
else:
|
||||
anchor = _find_section(rest, to)
|
||||
anchor = _find_section([r for r in rows if r["id"] != row["id"]], to)
|
||||
if anchor is None:
|
||||
raise ToolRejected("어디로 옮길지 못 찾았어요. '소개 다음으로' 처럼 말씀해 주세요.")
|
||||
at = rest.index(anchor) + 1
|
||||
moved, where = rest[:at] + [row] + rest[at:], f"{anchor['name']} 다음으로"
|
||||
moved, said = _move_by_anchor(rows, row, anchor, where)
|
||||
|
||||
await _save_sections(ctx, theme, moved)
|
||||
return f"{row['name']} 을(를) {where} 옮겼습니다."
|
||||
return f"{row['name']} 을(를) {said} 옮겼습니다."
|
||||
|
||||
|
||||
def _move_in_view(rows: list, row: dict, where: str, raw_count: str):
|
||||
"""한 칸 위·아래 · N번째 — 보이는 순서(_visible_rows)로 센다."""
|
||||
if not row["enabled"]:
|
||||
raise ToolRejected(f"{row['name']} 은(는) 지금 꺼져 있어 화면에 없는 부분이라 칸으로 옮길 수 없어요. "
|
||||
f"켠 뒤 말씀하시거나 '소개 다음으로' 처럼 말씀해 주세요.")
|
||||
view = _visible_rows(rows)
|
||||
at = next(i for i, r in enumerate(view) if r["id"] == row["id"])
|
||||
count = _count(raw_count) if raw_count else (None if where == "nth" else 1)
|
||||
if count is None or count < 1:
|
||||
raise ToolRejected("몇 칸인지, 몇 번째인지 숫자로 알려 주세요. 예) 세 번째로")
|
||||
|
||||
if where == "nth":
|
||||
if count > len(view):
|
||||
raise ToolRejected(f"1번째부터 {len(view)}번째 사이로 알려 주세요.")
|
||||
goal, said = count - 1, f"{count}번째로"
|
||||
elif where == "up":
|
||||
goal = max(0, at - count)
|
||||
said = f"{at - goal}칸 위로"
|
||||
else:
|
||||
goal = min(len(view) - 1, at + count)
|
||||
said = f"{goal - at}칸 아래로"
|
||||
if goal == at:
|
||||
edge = "맨 위에" if where == "up" else "맨 아래에" if where == "down" else f"{count}번째에"
|
||||
return Unchanged(f"{row['name']} 은(는) 이미 {edge} 있어요."), ""
|
||||
|
||||
others = [r for r in view if r["id"] != row["id"]]
|
||||
if goal < len(others):
|
||||
return _insert(rows, row, before=others[goal]), said
|
||||
return _insert(rows, row, after=others[-1]), said
|
||||
|
||||
|
||||
def _move_by_anchor(rows: list, row: dict, anchor: dict, where: str):
|
||||
"""앞 · 뒤 · 바꾸기. ★ 기준이 고정된 부분이면 — 히어로 다음은 맨 위, SNS 앞은 맨 아래로 읽고,
|
||||
그 밖(히어로 앞 · SNS 뒤 · 그 둘과 바꾸기)은 화면에 없는 자리라 거절한다."""
|
||||
rest = [r for r in rows if r["id"] != row["id"]]
|
||||
if anchor["id"] in PINNED:
|
||||
if (anchor["id"], where) == ("hero", "after"):
|
||||
return [row] + rest, "맨 위로"
|
||||
if (anchor["id"], where) == ("social", "before"):
|
||||
return rest + [row], "맨 아래로"
|
||||
raise ToolRejected(f"{anchor['name']} 은(는) 항상 {PINNED[anchor['id']]}에 서는 부분이라 "
|
||||
f"{'자리를 바꿀' if where == 'swap' else '그쪽으로 옮길'} 수 없어요.")
|
||||
if where == "before":
|
||||
return _insert(rows, row, before=anchor), f"{anchor['name']} 앞으로"
|
||||
if where == "after":
|
||||
return _insert(rows, row, after=anchor), f"{anchor['name']} 다음으로"
|
||||
i = next(k for k, r in enumerate(rows) if r["id"] == row["id"])
|
||||
j = next(k for k, r in enumerate(rows) if r["id"] == anchor["id"])
|
||||
swapped = list(rows)
|
||||
swapped[i], swapped[j] = swapped[j], swapped[i]
|
||||
return swapped, f"{anchor['name']} 와(과) 자리를 바꿔"
|
||||
|
||||
|
||||
# ── 사진 ─────────────────────────────────────────────────────────────────
|
||||
@@ -547,7 +690,8 @@ REGISTRY: dict[str, Tool] = {
|
||||
name="list_sections",
|
||||
grade=ToolGrade.READ,
|
||||
title="화면 구성 보기",
|
||||
summary="홈페이지가 어떤 부분들로 어떤 순서로 되어 있는지 보여준다.",
|
||||
summary="홈페이지가 어떤 부분들로 어떤 순서로 되어 있는지, 무엇이 꺼져 있는지 보여준다.",
|
||||
args={"only": "꺼진 부분만 보려면 '꺼진'(선택)"},
|
||||
run=_list_sections,
|
||||
),
|
||||
Tool(
|
||||
@@ -556,8 +700,8 @@ REGISTRY: dict[str, Tool] = {
|
||||
republish=True,
|
||||
describe=_describe_toggle,
|
||||
target=("name",),
|
||||
summary="홈페이지의 한 부분을 켜거나 끈다(예: 후기, 사진 갤러리, 예약 안내).",
|
||||
args={"name": "그 부분의 이름", "enabled": "켜면 true, 끄면 false"},
|
||||
summary="홈페이지의 부분을 켜거나 끈다(숨기기). 여러 부분을 한꺼번에 할 수 있다.",
|
||||
args={"name": "그 부분의 이름 — 여럿이면 쉼표로 이어서", "enabled": "켜면 true, 끄면 false"},
|
||||
run=_toggle_section,
|
||||
),
|
||||
Tool(
|
||||
@@ -567,7 +711,12 @@ REGISTRY: dict[str, Tool] = {
|
||||
describe=_describe_move,
|
||||
target=("name",),
|
||||
summary="홈페이지에서 한 부분의 위치(순서)를 바꾼다.",
|
||||
args={"name": "옮길 부분의 이름", "to": "'맨 위' · '맨 아래' · 또는 그 뒤에 올 부분의 이름"},
|
||||
args={
|
||||
"name": "옮길 부분의 이름",
|
||||
"where": "'맨 위' · '맨 아래' · '앞' · '뒤' · '위로' · '아래로' · '번째' · '바꾸기' 중 하나",
|
||||
"to": "앞·뒤·바꾸기의 기준이 되는 부분의 이름",
|
||||
"count": "위로·아래로는 칸 수, 번째는 순번(숫자)",
|
||||
},
|
||||
run=_move_section,
|
||||
),
|
||||
Tool(
|
||||
|
||||
Reference in new issue
Block a user