Skip to content

Commit e97b4dc

Browse files
committed
Make session persistence and doc sync boundaries explicit
Session persistence was still coupled tightly to doc generation inside saveSession and deleteSession. This pass extracts small internal helpers for normalization, raw file writes, docs synchronization, and raw file removal so the boundary is explicit while public behavior stays the same. Constraint: saveSession() and deleteSession() had to preserve current observable behavior under the runtime tests Constraint: This pass had to remain internal to session persistence and avoid a broader lifecycle redesign Rejected: Introduce a new public persistence API now | broader call-site migration than needed for this cleanup pass Rejected: Leave file persistence and docs sync interleaved inline | weaker separation of concerns and harder future changes Confidence: high Scope-risk: narrow Reversibility: clean Directive: Keep raw session file persistence and docs synchronization separable so future lifecycle changes can move them independently if needed Tested: bun test tests/runtime.test.ts Tested: bun run check Not-tested: Manual host-level save/reset flows outside automated tests
1 parent 3d113a6 commit e97b4dc

2 files changed

Lines changed: 42 additions & 14 deletions

File tree

analysis/ai-slop-cleanup-plan.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,12 @@
8181
1. Reduce nested inline conditionals in the render helpers without changing emitted markdown.
8282
2. Prefer simpler section assembly over larger template-string expressions.
8383
3. Keep file output, headings, and formatting stable under the existing render tests.
84+
85+
## Pass 8 Scope
86+
- `src/runtime/session.ts`
87+
- `tests/runtime.test.ts` as behavior lock
88+
89+
## Pass 8 Smell focus
90+
1. Split raw session persistence from docs synchronization helpers.
91+
2. Keep the public behavior of `saveSession()` and `deleteSession()` unchanged.
92+
3. Reduce coupling by making the file-write and docs-sync boundaries explicit.

src/runtime/session.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,34 @@ function now(): string {
88
return new Date().toISOString();
99
}
1010

11+
function normalizeSession(session: Session): Session {
12+
return SessionSchema.parse({
13+
...session,
14+
timestamps: {
15+
...session.timestamps,
16+
updatedAt: now(),
17+
},
18+
});
19+
}
20+
21+
async function writeSessionFile(worktree: string, session: Session): Promise<void> {
22+
const sessionPath = getSessionPath(worktree);
23+
await mkdir(worktree + "/.flow", { recursive: true });
24+
await writeFile(sessionPath, JSON.stringify(session, null, 2) + "\n", "utf8");
25+
}
26+
27+
async function syncSessionDocs(worktree: string, session: Session): Promise<void> {
28+
await renderSessionDocs(worktree, session);
29+
}
30+
31+
async function removeSessionFile(worktree: string): Promise<void> {
32+
await rm(getSessionPath(worktree), { force: true });
33+
}
34+
35+
async function removeSessionDocs(worktree: string): Promise<void> {
36+
await deleteSessionDocs(worktree);
37+
}
38+
1139
export async function loadSession(worktree: string): Promise<Session | null> {
1240
const sessionPath = getSessionPath(worktree);
1341

@@ -24,24 +52,15 @@ export async function loadSession(worktree: string): Promise<Session | null> {
2452
}
2553

2654
export async function saveSession(worktree: string, session: Session): Promise<Session> {
27-
const sessionPath = getSessionPath(worktree);
28-
const normalized = SessionSchema.parse({
29-
...session,
30-
timestamps: {
31-
...session.timestamps,
32-
updatedAt: now(),
33-
},
34-
});
35-
36-
await mkdir(worktree + "/.flow", { recursive: true });
37-
await writeFile(sessionPath, JSON.stringify(normalized, null, 2) + "\n", "utf8");
38-
await renderSessionDocs(worktree, normalized);
55+
const normalized = normalizeSession(session);
56+
await writeSessionFile(worktree, normalized);
57+
await syncSessionDocs(worktree, normalized);
3958
return normalized;
4059
}
4160

4261
export async function deleteSession(worktree: string): Promise<void> {
43-
await rm(getSessionPath(worktree), { force: true });
44-
await deleteSessionDocs(worktree);
62+
await removeSessionFile(worktree);
63+
await removeSessionDocs(worktree);
4564
}
4665

4766
export function createSession(goal: string, planning?: Partial<PlanningContext>): Session {

0 commit comments

Comments
 (0)