Skip to content

Commit

Permalink
always drop a trace from the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Aug 21, 2024
1 parent 26c511d commit 9a8dca0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
logVerbose,
logError,
delay,
dotGenaiscriptPath,
} from "../../core/src/util"
import { YAMLStringify } from "../../core/src/yaml"
import { PromptScriptRunOptions } from "../../core/src/server/messages"
Expand All @@ -63,6 +64,7 @@ import { resolveTokenEncoder } from "../../core/src/encoders"
import { appendFile, writeFile } from "fs/promises"

async function setupTraceWriting(trace: MarkdownTrace, filename: string) {
logVerbose(`writing trace to ${filename}`)
await ensureDir(dirname(filename))
await writeFile(filename, "", { encoding: "utf-8" })
trace.addEventListener(
Expand All @@ -85,7 +87,13 @@ export async function runScriptWithExitCode(
const runRetry = Math.max(1, normalizeInt(options.runRetry) || 1)
let exitCode = -1
for (let r = 0; r < runRetry; ++r) {
const res = await runScript(scriptId, files, options)
let outTrace = options.outTrace
if (!outTrace)
outTrace = dotGenaiscriptPath(
"runs",
`${new Date().toISOString().replace(/[:.]/g, "-")}.trace.md`

Check failure on line 94 in packages/cli/src/run.ts

View workflow job for this annotation

GitHub Actions / build

The function `dotGenaiscriptPath` might return a promise that is not being handled. Consider using `await` or `.then` to handle the promise.
)
const res = await runScript(scriptId, files, { ...options, outTrace })

Check failure on line 96 in packages/cli/src/run.ts

View workflow job for this annotation

GitHub Actions / build

Using the spread operator in the function call might lead to unexpected behavior if `options` is not a plain object. Consider validating `options` before spreading it.
exitCode = res.exitCode
if (
exitCode === SUCCESS_ERROR_CODE ||
Expand Down
3 changes: 2 additions & 1 deletion packages/vscode/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ export class ExtensionState extends EventTarget {
await writeFile(
dir,
".gitignore",
`cache/
`runs/
cache/

Check failure on line 182 in packages/vscode/src/state.ts

View workflow job for this annotation

GitHub Actions / build

Hardcoding directory names like `runs/` and `cache/` can lead to potential issues in the future. Consider using a configuration or environment variable for these values.
retrieval/
containers/
temp/
Expand Down

0 comments on commit 9a8dca0

Please sign in to comment.