@@ -1020,27 +1020,57 @@ def _collect_running_html(name: str | None = None) -> str:
10201020 )
10211021
10221022
1023- def _collect_changes_html (limit : int = 30 , name : str | None = None ) -> str :
1023+ def _changes_filter_html (name : str | None , sweep : str | None ) -> str :
1024+ """「どの回を見るか」の切り替え。**回が 1 本しかなければ出さない**(選ぶ先が無い)。
1025+
1026+ 押した先はこの節へ戻す(`#changes`)—— 長い面の途中にある表なので、
1027+ 絞り込んだ結果が画面の外に出ていると、押しても何も起きていないように見える。
1028+ """
1029+ names = collect_log .sweeps (name )
1030+ if len (names ) < 2 :
1031+ return ""
1032+ base = f"/admin/collect/{ quote (name )} " if name else "/admin/memory"
1033+ links = [("すべて" , None ), * ((one , one ) for one in names )]
1034+ out = []
1035+ for label , value in links :
1036+ href = f"{ base } ?sweep={ quote (value )} #changes" if value else f"{ base } #changes"
1037+ out .append (
1038+ f"<strong>{ esc (label )} </strong>" if value == sweep
1039+ else f'<a href="{ esc (href )} ">{ esc (label )} </a>'
1040+ )
1041+ return f'<p class="muted">どの回を見るか: { " / " .join (out )} </p>'
1042+
1043+
1044+ def _collect_changes_html (
1045+ limit : int = 30 , name : str | None = None , sweep : str | None = None ,
1046+ ) -> str :
10241047 """直近どこに修正が入ったか(`app/collect_log.py`)。
10251048
10261049 **表の「前回」列とは別に要る。** あちらは最新の 1 回で上書きされるので、
10271050 6 時間ごとに回る収集なら朝には昨夜の 1 回しか残っていない。減り続けているのか、
10281051 ある日だけ荒れたのかは、並べて初めて読める。
10291052
1053+ **回で絞れるようにする。** 間隔は回ごとに桁違いなので、新しい順に並べるだけでは
1054+ **短い回が長い回を押し流す** —— 1 時間ごとの回が 24 行を占めれば、4 時間ごとの
1055+ 回の差分は 1 日ぶんも残らない。読みたいのは「整理が何を直したか」のほうなのに。
1056+
10301057 **控えの置き場が無ければ、何も出さずに理由だけ出す** —— 空の表を出すと
10311058 「まだ動いていない」と読めてしまう(実際は記録していないだけ)。
10321059 """
10331060 if collect_log .db_path () is None :
10341061 return (
1035- '<details><summary>直近の変更</summary>'
1062+ '<details id="changes" ><summary>直近の変更</summary>'
10361063 '<p class="muted">変更履歴は記録していません。'
10371064 "<code>CHIEZO_STATE_DIR</code> を設定すると残ります。</p></details>"
10381065 )
1039- changes = collect_log .recent (name , limit = limit )
1066+ picker = _changes_filter_html (name , sweep )
1067+ changes = collect_log .recent (name , limit = limit , sweep = sweep )
10401068 if not changes :
10411069 return (
1042- '<details><summary>直近の変更</summary>'
1043- '<p class="muted">まだ 1 回も走っていません。</p></details>'
1070+ f'<details id="changes" open><summary>直近の変更</summary>{ picker } '
1071+ '<p class="muted">'
1072+ + ("その回はまだ走っていません。" if sweep else "まだ 1 回も走っていません。" )
1073+ + "</p></details>"
10441074 )
10451075 rows = []
10461076 for row in changes :
@@ -1107,7 +1137,8 @@ def _collect_changes_html(limit: int = 30, name: str | None = None) -> str:
11071137 f'<td>{ summary } { note } </td><td>{ row ["total" ]:,} 件{ detail } </td></tr>'
11081138 )
11091139 return f"""
1110- <details open><summary>直近の変更</summary>
1140+ <details id="changes" open><summary>直近の変更</summary>
1141+ { picker }
11111142<table>
11121143<thead><tr><th>いつ</th>{ "" if name else "<th>収集</th>" } <th>どの回</th><th>頼んだ相手</th>
11131144<th>かかった</th><th>変化</th><th>焼いた後</th></tr></thead>
@@ -1274,7 +1305,9 @@ def _collect_detail_html(item, disabled: str, sources: dict | None = None) -> st
12741305 )
12751306
12761307
1277- def _collect_html (sources : dict [str , Source ], disabled : str ) -> str :
1308+ def _collect_html (
1309+ sources : dict [str , Source ], disabled : str , sweep : str | None = None ,
1310+ ) -> str :
12781311 """収集(AI に集めさせて溜めていく)の節。
12791312
12801313 **出すのは「間隔・次にいつ走るか・いま何件」の 3 つ**。無人で回る層なので、
@@ -1384,7 +1417,7 @@ def _collect_html(sources: dict[str, Source], disabled: str) -> str:
13841417 return f"""
13851418{ table }
13861419{ _collect_running_html ()}
1387- { _collect_changes_html ()}
1420+ { _collect_changes_html (sweep = sweep )}
13881421<details><summary>収集を追加する</summary>
13891422<form method="post" action="/admin/collect/create" class="collect-form">
13901423<p><label>name(ソース名になる。英小文字・数字・_)<br>
@@ -1786,7 +1819,10 @@ def _running_html(running: list[dict]) -> str:
17861819
17871820
17881821@router .get ("/admin/memory" , response_class = HTMLResponse )
1789- def admin_memory (request : Request ):
1822+ def admin_memory (
1823+ request : Request ,
1824+ sweep : str | None = Query (None , description = "直近の変更を、この回のぶんだけに絞る" ),
1825+ ):
17901826 sources : dict [str , Source ] = request .app .state .sources
17911827 job = _fetch_trigger_status ()
17921828 disabled = run_buttons_disabled (job )
@@ -1925,7 +1961,7 @@ def schema_cell(version: int) -> str:
19251961</details>
19261962
19271963<h2 id="collect">集める(AI に集めさせて溜める)</h2>
1928- { _collect_html (sources , disabled )}
1964+ { _collect_html (sources , disabled , sweep )}
19291965
19301966<h2 id="consolidation">短期記憶から移す(固化)</h2>
19311967{ _memory_html (sources , disabled )}
@@ -2843,7 +2879,11 @@ def _preview_page_html(name: str, result: dict | None, error: str) -> str:
28432879
28442880
28452881@router .get ("/admin/collect/{name}" , response_class = HTMLResponse )
2846- def admin_collect_detail (request : Request , name : str ):
2882+ def admin_collect_detail (
2883+ request : Request ,
2884+ name : str ,
2885+ sweep : str | None = Query (None , description = "直近の変更を、この回のぶんだけに絞る" ),
2886+ ):
28472887 """収集 1 つぶんの面。**一覧から名前を押すとここへ来る**。
28482888
28492889 **一覧の中で開かない。** 折り畳みの中に押し込んでいた頃は、開くたびに表が縦へ
@@ -2883,7 +2923,7 @@ def admin_collect_detail(request: Request, name: str):
28832923</table>
28842924{ _collect_detail_html (item , disabled , request .app .state .sources )}
28852925{ _collect_running_html (name )}
2886- { _collect_changes_html (name = name )}
2926+ { _collect_changes_html (name = name , sweep = sweep )}
28872927<p class="muted"><a href="/admin/memory#collect">集める の一覧へ戻る</a></p>
28882928"""
28892929 return HTMLResponse (content = page_shell (name , body ))
0 commit comments