MCPcopy Index your code
hub / github.com/anomalyco/opencode / trace

Function trace

packages/opencode/src/cli/cmd/run/trace.ts:53–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51}
52
53export function trace(): Trace | undefined {
54 if (state !== undefined) {
55 return state || undefined
56 }
57
58 if (!process.env.OPENCODE_DIRECT_TRACE) {
59 state = false
60 return undefined
61 }
62
63 const target = file()
64 fs.mkdirSync(path.dirname(target), { recursive: true })
65 fs.writeFileSync(
66 latest(),
67 text({
68 time: new Date().toISOString(),
69 pid: process.pid,
70 cwd: process.cwd(),
71 argv: process.argv.slice(2),
72 path: target,
73 }) + "\n",
74 )
75 state = {
76 write(type: string, data?: unknown) {
77 fs.appendFileSync(
78 target,
79 text({
80 time: new Date().toISOString(),
81 pid: process.pid,
82 type,
83 data,
84 }) + "\n",
85 )
86 },
87 }
88 state.write("trace.start", {
89 argv: process.argv.slice(2),
90 cwd: process.cwd(),
91 path: target,
92 })
93 return state
94}

Callers 1

runInteractiveRuntimeFunction · 0.90

Calls 5

writeMethod · 0.80
fileFunction · 0.70
latestFunction · 0.70
textFunction · 0.70
cwdMethod · 0.65

Tested by

no test coverage detected