@arcreflex/agent-transcripts 0.1.14 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcreflex/agent-transcripts",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "Transform AI coding agent session files into readable transcripts",
5
5
  "type": "module",
6
6
  "repository": {
package/src/archive.ts CHANGED
@@ -10,6 +10,7 @@ import { homedir } from "os";
10
10
  import { mkdir, readdir, rename, unlink } from "fs/promises";
11
11
  import type { Adapter, DiscoveredSession, Transcript } from "./types.ts";
12
12
  import { extractSessionId } from "./utils/naming.ts";
13
+ import { renderTranscript } from "./render.ts";
13
14
 
14
15
  export const DEFAULT_ARCHIVE_DIR = join(
15
16
  process.env.XDG_DATA_HOME || join(homedir(), ".local/share"),
@@ -119,6 +120,35 @@ export async function saveEntry(
119
120
  }
120
121
  }
121
122
 
123
+ function renderEntryMarkdown(entry: ArchiveEntry): string {
124
+ return entry.transcripts
125
+ .map((t, i) =>
126
+ renderTranscript(t, {
127
+ sourcePath: i === 0 ? entry.sourcePath : undefined,
128
+ }),
129
+ )
130
+ .join("\n\n---\n\n");
131
+ }
132
+
133
+ async function saveMarkdown(
134
+ archiveDir: string,
135
+ entry: ArchiveEntry,
136
+ ): Promise<void> {
137
+ const filePath = join(archiveDir, `${entry.sessionId}.md`);
138
+ const tmpPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
139
+ const content = renderEntryMarkdown(entry);
140
+
141
+ await Bun.write(tmpPath, content);
142
+ try {
143
+ await rename(tmpPath, filePath);
144
+ } catch (err) {
145
+ try {
146
+ await unlink(tmpPath);
147
+ } catch {}
148
+ throw err;
149
+ }
150
+ }
151
+
122
152
  export function isFresh(
123
153
  entry: ArchiveEntry,
124
154
  sourceHash: string,
@@ -146,8 +176,16 @@ export async function archiveSession(
146
176
  if (session.summary && existing.title !== session.summary) {
147
177
  existing.title = session.summary;
148
178
  await saveEntry(archiveDir, existing);
179
+ await saveMarkdown(archiveDir, existing);
149
180
  return { entry: existing, updated: true };
150
181
  }
182
+
183
+ // Backfill .md if missing (upgrade path for pre-markdown archives)
184
+ const mdPath = join(archiveDir, `${sessionId}.md`);
185
+ if (!(await Bun.file(mdPath).exists())) {
186
+ await saveMarkdown(archiveDir, existing);
187
+ }
188
+
151
189
  return { entry: existing, updated: false };
152
190
  }
153
191
 
@@ -166,6 +204,7 @@ export async function archiveSession(
166
204
  };
167
205
 
168
206
  await saveEntry(archiveDir, entry);
207
+ await saveMarkdown(archiveDir, entry);
169
208
  return { entry, updated: true };
170
209
  }
171
210
 
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it, beforeEach, afterEach } from "bun:test";
2
2
  import { join } from "path";
3
- import { mkdtemp, rm } from "fs/promises";
3
+ import { mkdtemp, readdir, rm, unlink } from "fs/promises";
4
4
  import { tmpdir } from "os";
5
5
  import {
6
6
  archiveSession,
@@ -176,6 +176,49 @@ describe("archiveSession", () => {
176
176
  expect(loaded?.title).toBe("New harness title");
177
177
  });
178
178
 
179
+ it("writes .md alongside .json", async () => {
180
+ const fixturePath = join(fixturesDir, "basic-conversation.input.jsonl");
181
+ const session = {
182
+ path: fixturePath,
183
+ relativePath: "basic-conversation.input.jsonl",
184
+ mtime: Date.now(),
185
+ };
186
+
187
+ const { entry } = await archiveSession(tmpDir, session, claudeCodeAdapter);
188
+
189
+ const mdPath = join(tmpDir, `${entry.sessionId}.md`);
190
+ const md = await Bun.file(mdPath).text();
191
+ expect(md).toContain("# Transcript");
192
+ expect(md).toContain(fixturePath);
193
+ });
194
+
195
+ it("backfills .md when json is fresh but .md is missing", async () => {
196
+ const fixturePath = join(fixturesDir, "basic-conversation.input.jsonl");
197
+ const session = {
198
+ path: fixturePath,
199
+ relativePath: "basic-conversation.input.jsonl",
200
+ mtime: Date.now(),
201
+ };
202
+
203
+ // Archive once (creates both .json and .md)
204
+ const { entry } = await archiveSession(tmpDir, session, claudeCodeAdapter);
205
+
206
+ // Delete the .md to simulate a pre-markdown archive
207
+ const mdPath = join(tmpDir, `${entry.sessionId}.md`);
208
+ await unlink(mdPath);
209
+
210
+ // Re-archive — json is fresh, but .md should be backfilled
211
+ const { updated } = await archiveSession(
212
+ tmpDir,
213
+ session,
214
+ claudeCodeAdapter,
215
+ );
216
+ expect(updated).toBe(false);
217
+
218
+ const md = await Bun.file(mdPath).text();
219
+ expect(md).toContain("# Transcript");
220
+ });
221
+
179
222
  it("preserves existing title when re-archiving", async () => {
180
223
  const fixturePath = join(fixturesDir, "basic-conversation.input.jsonl");
181
224
  const session = {