oc-transcript-save 0.2.0 → 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> {
@@ -292,15 +293,14 @@ export const TranscriptSavePluginV2 = {
292
293
  const sessionID = resolveSessionId(event)
293
294
  if (!sessionID) return
294
295
 
295
- if (type === 'session.status') {
296
- const status = asObject(asObject(event.data).status)
297
- const statusType = asString(status.type)
298
- if (statusType === 'busy' || statusType === 'retry') return
299
- if (statusType === 'idle') schedule(sessionID)
300
- return
301
- }
302
-
303
- if (type === 'session.idle') {
296
+ // V2 replaced the ephemeral `session.status` / deprecated `session.idle`
297
+ // bus events (never delivered to plugins) with durable
298
+ // `session.execution.*` events. A turn ends in exactly one of these.
299
+ if (
300
+ type === 'session.execution.succeeded'
301
+ || type === 'session.execution.failed'
302
+ || type === 'session.execution.interrupted'
303
+ ) {
304
304
  schedule(sessionID)
305
305
  }
306
306
  }
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.0",
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')