oc-transcript-save 0.2.1 → 0.2.2

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/index.ts CHANGED
@@ -28,6 +28,7 @@ import {
28
28
  toYaml,
29
29
  truncateText,
30
30
  } from './transcript-save.ts'
31
+ import path from 'node:path'
31
32
 
32
33
  const SERVICE_NAME = 'oc-transcript-save'
33
34
 
@@ -218,7 +219,7 @@ function resolveOutputPath(ctx: AnyCtx, snapshot: Snapshot): string {
218
219
  const timestamp = formatFilenameTimestamp(time.created)
219
220
  const id = sanitiseFilename(asString(session.id, 'unknown-session'))
220
221
  const root = process.env.OC_TRANSCRIPT_SAVE_PATH || asString(ctx.location?.directory, '') || process.cwd()
221
- return `${root.replace(/\/+$/, '')}/${timestamp}-${id}.md`
222
+ return path.join(root, `${timestamp}-${id}.md`)
222
223
  }
223
224
 
224
225
  async function fetchSnapshot(ctx: AnyCtx, sessionID: string): Promise<Snapshot> {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oc-transcript-save",
3
3
  "description": "OpenCode plugin that autosaves full transcript in specified directory",
4
- "version": "0.2.1",
4
+ "version": "0.2.2",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
7
7
  "module": "./index.ts",
@@ -596,8 +596,20 @@ export async function atomicWrite(filePath: string, content: string): Promise<nu
596
596
  try {
597
597
  await rename(tmpPath, filePath)
598
598
  } catch (error) {
599
- await unlink(tmpPath).catch(() => undefined)
600
- throw error
599
+ // POSIX rename atomically replaces the destination; Windows refuses to
600
+ // rename onto an existing file (EEXIST/EPERM). Remove it and retry.
601
+ if (process.platform === 'win32') {
602
+ await unlink(filePath).catch(() => undefined)
603
+ try {
604
+ await rename(tmpPath, filePath)
605
+ } catch (retryError) {
606
+ await unlink(tmpPath).catch(() => undefined)
607
+ throw retryError
608
+ }
609
+ } else {
610
+ await unlink(tmpPath).catch(() => undefined)
611
+ throw error
612
+ }
601
613
  }
602
614
 
603
615
  return Buffer.byteLength(normalised, 'utf8')