Archive transcripts as private as their session files

This commit is contained in:
2026-09-24 20:23:53 +02:00
parent 839804f47e
commit 0bfbfa53c1
2 changed files with 21 additions and 2 deletions
+4 -2
View File
@@ -153,10 +153,12 @@ def archive(path, note):
folder = os.path.join(ARCHIVE, project_path())
try:
stamp = time.strftime("%Y-%m-%dT%H-%M-%SZ", time.gmtime(os.path.getmtime(path)))
os.makedirs(folder, exist_ok=True)
os.makedirs(folder, mode=0o700, exist_ok=True)
os.chmod(ARCHIVE, 0o700)
dest = os.path.join(folder, f"{stamp}.md")
if not os.path.exists(dest):
open(dest, "w", encoding="utf-8").write(f"# {stamp} {project_path()}\n\n{note}\n\n{render(entries(path))}\n")
with open(os.open(dest, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600), "w", encoding="utf-8") as copy:
copy.write(f"# {stamp} {project_path()}\n\n{note}\n\n{render(entries(path))}\n")
print(f"transcript: {dest}", file=sys.stderr)
except OSError as failure:
print(f"could not archive the transcript: {failure}", file=sys.stderr)
+17
View File
@@ -1,6 +1,10 @@
import importlib.machinery
import importlib.util
import json
import os
import pathlib
import stat
import tempfile
import unittest
LOADER = importlib.machinery.SourceFileLoader("loop_claude", str(pathlib.Path(__file__).with_name("loop-claude")))
@@ -65,6 +69,19 @@ class JudgePrompt(unittest.TestCase):
self.assertTrue(prompt.endswith(loop.JUDGE_RULES))
class Archive(unittest.TestCase):
def test_keeps_the_copy_as_private_as_the_transcript(self):
with tempfile.TemporaryDirectory() as root:
transcript = os.path.join(root, "session.jsonl")
open(transcript, "w").write(json.dumps(assistant({"type": "text", "text": "said"})) + "\n")
loop.ARCHIVE = os.path.join(root, "archive")
loop.archive(transcript, "note")
[copy] = [os.path.join(folder, name) for folder, _, names in os.walk(loop.ARCHIVE) for name in names]
self.assertEqual(stat.S_IMODE(os.stat(copy).st_mode), 0o600)
self.assertEqual(stat.S_IMODE(os.stat(os.path.dirname(copy)).st_mode), 0o700)
self.assertIn("said", open(copy).read())
class Grounded(unittest.TestCase):
def test_an_interrupt_must_quote_the_transcript(self):
self.assertTrue(loop.grounded({"ask": False, "evidence": ""}, "anything"))