Claude の作業区間を n8n の work_log へ送る「n8n へ送る」タブを追加 #2
+8
-2
@@ -1312,8 +1312,14 @@ def collect_blocks(store, project_id, start, end, gap_min=N8N_GAP_MIN, min_min=N
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
out.append(block)
|
out.append(block)
|
||||||
out.sort(key=lambda b: b["startEpoch"])
|
# 会話を続けると新しいセッションのファイルに前の履歴が同じ時刻のまま写されるので、
|
||||||
return out
|
# 開始時刻 (ミリ秒) が同じ区間は写しとみなし、いちばん後まで続いているものだけを残す。
|
||||||
|
unique = {}
|
||||||
|
for block in out:
|
||||||
|
key = int(round(block["startEpoch"] * 1000))
|
||||||
|
if key not in unique or block["endEpoch"] > unique[key]["endEpoch"]:
|
||||||
|
unique[key] = block
|
||||||
|
return sorted(unique.values(), key=lambda b: b["startEpoch"])
|
||||||
|
|
||||||
|
|
||||||
def mark_blocks(blocks, rows, deleted_sources, now=None):
|
def mark_blocks(blocks, rows, deleted_sources, now=None):
|
||||||
|
|||||||
@@ -153,6 +153,16 @@ class CollectAndMarkTest(unittest.TestCase):
|
|||||||
self.assertEqual([b["date"] for b in day1], ["2026-01-05"])
|
self.assertEqual([b["date"] for b in day1], ["2026-01-05"])
|
||||||
self.assertEqual(day2, [])
|
self.assertEqual(day2, [])
|
||||||
|
|
||||||
|
def test_continued_session_copies_are_listed_once(self):
|
||||||
|
# 会話を続けると、新しいセッションのファイルに前の履歴が同じ時刻のまま写される
|
||||||
|
old = [(0, "user", "設計して"), (10, "assistant", "ok")]
|
||||||
|
write_session(self.root, "C--debug-demo", "old", old, r"C:\debug\demo")
|
||||||
|
write_session(self.root, "C--debug-demo", "new",
|
||||||
|
old + [(20, "user", "続き"), (25, "assistant", "ok"), (90, "user", "次"), (100, "assistant", "ok")],
|
||||||
|
r"C:\debug\demo")
|
||||||
|
blocks = chktime.collect_blocks(self.store, "", date(2026, 1, 5), date(2026, 1, 5), 30, 5, now=LATER)
|
||||||
|
self.assertEqual([(b["sessionId"], b["minutes"]) for b in blocks], [("new", 25), ("new", 10)])
|
||||||
|
|
||||||
def test_mark_blocks(self):
|
def test_mark_blocks(self):
|
||||||
b1 = {"source": "chktime:a:1", "startEpoch": BASE, "endEpoch": BASE + 600, "start": "", "end": "", "taskName": "A"}
|
b1 = {"source": "chktime:a:1", "startEpoch": BASE, "endEpoch": BASE + 600, "start": "", "end": "", "taskName": "A"}
|
||||||
b2 = {"source": "chktime:b:2", "startEpoch": BASE + 600, "endEpoch": BASE + 1200, "start": "", "end": "", "taskName": "B"}
|
b2 = {"source": "chktime:b:2", "startEpoch": BASE + 600, "endEpoch": BASE + 1200, "start": "", "end": "", "taskName": "B"}
|
||||||
|
|||||||
Reference in New Issue
Block a user